[vtkusers] Proper way to append to vtkPoints

Cory Quammen cory.quammen at kitware.com
Mon Sep 19 11:01:48 EDT 2016


Bud,

Please keep messages on the list so that others may contribute to and
benefit from the conversation.

Your example is okay for VTK 7, but GetVoidPointer() may be going away
at some point in the future.

David, do you have a more future-proof way to do bulk copying of data
into data arrays?

Thanks,
Cory

On Thu, Sep 15, 2016 at 12:34 PM, Bud Bundy <budric at gmail.com> wrote:
> That works, thank you.  I was tempted by the documentation for SetPoint: "No
> range checking performed (fast!)." to use that function.
>
> In order to speed things up further I actually have some points stored in
> contiguous memory.  I wrote the following and it seems to work to append
> tuple data.  Can I get a second opinion if this is decent code to append to
> vtkPoints using memcpy()?  There's a comment under
> vtkAbstractArray::GetVoidPointer() that "as newer arrays require a deep-copy
> of the array data in order to return a suitable pointer" and I'm not sure
> what that means.
>
> void appendPoints(vtkSmartPointer<vtkPoints> target, const double *
> vec3Data, size_t numInputPoints)
> {
>     //some assertions that target storage type is double, and number of
> componnets == 3 and app specific exceptions
>     //...
>     //
>
>     //resize
>     size_t allocatedPoints = (target->GetData()->GetSize()) / 3;
>     size_t numStoredPoints = (target->GetData()->GetNumberOfTuples());
>     size_t requiredAllocatePoints = numStoredPoints + numInputPoints;
>     if (allocatedPoints < requiredAllocatePoints)
>     {
>         target->Resize(requiredAllocatePoints);
>     }
>     //copy data
>     double * targetMemPtr = (double*)target->GetVoidPointer(numStoredPoints
> * 3);
>     memcpy(targetMemPtr, vec3Data, numInputPoints * 3 * sizeof(double));
>
>     //update point count
> target->GetData()->SetNumberOfTuples(requiredAllocatePoints);
>
> }
>
>
> On 09/14/2016 02:50 PM, Cory Quammen wrote:
>>
>> For expanding the list of points, use points->InsertPoint(1, 1, 1, 1)
>> instead of points->SetPoint(1, 1, 1, 1).
>>
>> HTH,
>> Cory
>>
>> On Wed, Sep 14, 2016 at 2:43 PM, Bud Bundy <budric at gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> What's the proper, efficient way to append point data to vtkPoints?  The
>>> following does not work (assume 2 batches insert thousands of points not
>>> 1
>>> per each batch)
>>>
>>>      vtkSmartPointer<vtkPoints> points =
>>> vtkSmartPointer<vtkPoints>::New();
>>>      points->SetNumberOfPoints(1);        //first batch insert
>>>      points->SetPoint(0, 0, 0, 0);
>>>      points->Resize(2);                    //second batch insert
>>>      points->SetPoint(1, 1, 1, 1);
>>>      size_t size = points->GetNumberOfPoints();
>>>      //size == 1 not 2
>>>
>>> I'm using VTK 7.0.0.
>>>
>>> Thank you.
>>>
>>> _______________________________________________
>>> 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:
>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>



-- 
Cory Quammen
Staff R&D Engineer
Kitware, Inc.


More information about the vtkusers mailing list