[Paraview] vtkDoubleArray with >3 components

Bruce Jones bruce.david.jones at gmail.com
Wed Jul 22 11:21:27 EDT 2015


Thanks Berk,

I have tried with both zero and 1 as the save argument and am getting the
same behavior. As before, if I comment the SetNumberOfComponents call (or
set number of components to 1) everything works, except I only have single
component arrays in the output.

I'm going to put together a minimum working example with the issue this
afternoon so that I can show you guys in more detail.

Cheers,
Bruce

On Wed, 22 Jul 2015 at 11:09 Berk Geveci <berk.geveci at kitware.com> wrote:

> The solution is in the documentation:
>
>   // This method lets the user specify data to be held by the array.  The
>   // array argument is a pointer to the data.  size is the size of the
>   // array supplied by the user.  Set save to 1 to keep the class from
>   // deleting the array when it cleans up or reallocates memory.  The class
>   // uses the actual array provided; it does not copy the data from the
>   // suppled array. If specified, the delete method determines how the data
>   // array will be deallocated. If the delete method is
>   // VTK_DATA_ARRAY_FREE, free() will be used. If the delete method is
>   // DELETE, delete[] will be used. The default is FREE.
>
> You are passing 0 for the "save" argument, which means that VTK will
> delete the array when the VTK array object is deleted, which would cause a
> double delete/free. Use 1 as the second argument of SetArray() if you are
> managing the memory. Also, make sure that the VTK array is not used after
> you free your array.
>
> Best,
> -berk
>
> On Wed, Jul 22, 2015 at 9:56 AM, Bruce Jones <bruce.david.jones at gmail.com>
> wrote:
>
>> Hi Guys,
>>
>> I have just tried it as you suggested, doing SetNumberOfComponents then
>> SetArray, without doing SetNumberOfTuples. Unfortunately I am still getting
>> the same behaviour.
>>
>> Cheers,
>> Bruce
>>
>> On Wed, 22 Jul 2015 at 09:44 Berk Geveci <berk.geveci at kitware.com> wrote:
>>
>>> Actually, don't call SetNumberOfTuples() at all if you are using
>>> SetArray(). It will unnecessarily allocate memory if you call it before
>>> SetArray().
>>>
>>> -berk
>>>
>>> On Wed, Jul 22, 2015 at 9:40 AM, Shawn Waldon <shawn.waldon at kitware.com>
>>> wrote:
>>>
>>>> Hi Bruce,
>>>>
>>>> SetNumberOfTuples reallocates the internal datastructure of the data
>>>> array to be the new required size based on the new number of components and
>>>> number of tuples.  This (combined with trying to clean up the old data from
>>>> SetArray) may be causing the heap corruption you are seeing.  Try setting
>>>> the number of components and number of tuples before adding the data to the
>>>> array.
>>>>
>>>> HTH,
>>>> Shawn
>>>>
>>>> On Tue, Jul 21, 2015 at 1:37 PM, Bruce Jones <
>>>> bruce.david.jones at gmail.com> wrote:
>>>>
>>>>> Hi Cory,
>>>>>
>>>>> Sorry for the delayed response, I've hit another more serious bug
>>>>> which has been diverting my attention from this.
>>>>>
>>>>> Thanks for the state file, I haven't got it to work as I don't have
>>>>> numpy set up, but I have also got this working with 9 component arrays in
>>>>> paraview using a python script. However, I am now trying to port my python
>>>>> plugin to c++ which is where I am seeing the error.
>>>>>
>>>>> In my plugin I want to output a vtkarray for each vtkarray in the
>>>>> input dataset. The values in the output vtkarrays are interpolated from
>>>>> those in the input vtkarrays. Rather than working directly on vtkarray
>>>>> objects, I am allocating c++ arrays for each vtkarray, performing the
>>>>> interpolation, then creating vtkDoubleArrays and using SetArray to pass a
>>>>> pointer to my allocated c++ arrays to the output vtkarrays. The code for
>>>>> setting up the output vtkarrays is roughly as follows
>>>>>
>>>>>                 vtkPointData *pointData = input->GetPointData();
>>>>>                 vtkDataArray *dArray = pointData->GetArray(i);
>>>>> vtkDoubleArray *vtkDArrayAve = vtkDoubleArray::New();
>>>>> vtkDArrayAve->SetName(dArray->GetName());
>>>>> vtkDArrayAve->SetArray(dArraysAve[i],hgrid->GetTotalCells(),0);
>>>>> vtkDArrayAve->SetNumberOfComponents(numComponents[i]);
>>>>> vtkDArrayAve->SetNumberOfTuples(hgrid->GetTotalCells());
>>>>> output->GetPointData()->AddArray(vtkDArrayAve);
>>>>>
>>>>> dArraysAve is an array of pointers pointing to my c++ arrays
>>>>> hgrid->GetTotalCells() returns the number of data points for my output
>>>>>
>>>>> I also have another mode of operation for this plugin, where I perform
>>>>> the interpolation differently, in that function, if I make the call to
>>>>> SetNumberOfComponents() some heap corruption occurs and I get a segfault
>>>>> when I try to subsequently free my c++ arrays. Commenting out the call to
>>>>> SetNumberOfComponents avoids the segfault, but then I am limited to single
>>>>> component arrays. This is the more serious bug I mentioned, initially I
>>>>> figured they were unrelated, but I can't deny the number of components
>>>>> coincidence.
>>>>>
>>>>> Cheers,
>>>>> Bruce
>>>>>
>>>>> On Thu, 16 Jul 2015 at 14:41 Cory Quammen <cory.quammen at kitware.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Bruce,
>>>>>>
>>>>>> I have attached a ParaView state file with a Programmable Source that
>>>>>> produces a vtkPolyData with 100 random points and a point data array with 9
>>>>>> components. It seems to display the various component ranges just fine.
>>>>>>
>>>>>> Best,
>>>>>> Cory
>>>>>>
>>>>>> On Thu, Jul 16, 2015 at 11:14 AM, Cory Quammen <
>>>>>> cory.quammen at kitware.com> wrote:
>>>>>>
>>>>>>> Hi Bruce,
>>>>>>>
>>>>>>> I haven't seen this, but ParaView may be interpreting this array as
>>>>>>> a tensor field. Do you have a smallish test data file that you can share
>>>>>>> that shows the problem?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Cory
>>>>>>>
>>>>>>> On Sat, Jul 11, 2015 at 11:14 AM, Bruce Jones <
>>>>>>> bruce.david.jones at gmail.com> wrote:
>>>>>>>
>>>>>>>> I am creating vtkDoubleArrays based on averaging some input data to
>>>>>>>> a reduced set of points. The input data includes various vtk arrays which
>>>>>>>> have 1, 3 and 9 components.
>>>>>>>>
>>>>>>>> After averaging, I am writing the data to c++ arrays, and creating
>>>>>>>> a new vtkDoubleArray using the SetArray() function to pass the c++ arrays.
>>>>>>>> This works fine for 1 and 3 component arrays, however for the 9 component
>>>>>>>> arrays paraview shows that every element is set to 0.
>>>>>>>>
>>>>>>>> If I hardcode it so that 9 component arrays become 3 component
>>>>>>>> arrays (reading only the first 3 components from the input array), then I
>>>>>>>> get the correct data for the first 3 components, though I obviously need
>>>>>>>> the other 6 components in the end.
>>>>>>>>
>>>>>>>> Has anyone encountered this before?
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Bruce
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> 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 ParaView Wiki at:
>>>>>>>> http://paraview.org/Wiki/ParaView
>>>>>>>>
>>>>>>>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>>>>>>>
>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>> http://public.kitware.com/mailman/listinfo/paraview
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Cory Quammen
>>>>>>> R&D Engineer
>>>>>>> Kitware, Inc.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Cory Quammen
>>>>>> R&D Engineer
>>>>>> Kitware, Inc.
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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 ParaView Wiki at:
>>>>> http://paraview.org/Wiki/ParaView
>>>>>
>>>>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://public.kitware.com/mailman/listinfo/paraview
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> 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 ParaView Wiki at:
>>>> http://paraview.org/Wiki/ParaView
>>>>
>>>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/paraview
>>>>
>>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20150722/8153320e/attachment.html>


More information about the ParaView mailing list