[vtkusers] How to get data ptr from the vtkpolydata?

Lin M majcjc at gmail.com
Wed Sep 17 07:52:38 EDT 2014


Thank you for your advice, David.

I made a mistake, m_SkullMesh is a vtkOBJReader and the
m_SkullMesh->GetOutput() should be a vtkPolyData.

I hope to get the point array of it. The code I wrote before could work
properly

int meshNum = m_SkullMesh->GetOutput()->GetNumberOfPoints();
double *skullTemplate = new double[3*meshNum];
for(int i = 0; i < meshNum; ++i) {
double* temp = m_SkullMesh->GetOutput()->GetPoint(i);
skullTemplate[3*i] = temp[0];
skullTemplate[3*i+1] = temp[1];
skullTemplate[3*i+2] = temp[2];
}

But I think it should have a better way to avoid the copy and get the data
pointer directly. Can you give me some suggestion? Thank you!

Best,
Lin


On Wed, Sep 17, 2014 at 7:41 PM, David Doria <daviddoria at gmail.com> wrote:

> On Wed, Sep 17, 2014 at 7:17 AM, Lin M <majcjc at gmail.com> wrote:
>
>> Hi all,
>>
>> I try to get the data ptr which I think is a double * pointing to a
>> double array from vtkpolydata but I met an access violation when I use
>>
>> double *skullTemplate =
>> vtkDoubleArray::SafeDownCast(m_SkullMesh->GetOutput()->GetPoints()->GetData())->GetPointer(0);
>>
>> m_SkullMesh is a vtkPolyData.
>>
>> How can I do to get it work? Thank you!
>>
>> Best,
>> Lin
>>
>
> Please post the smallest, compilable code you can that demonstrates the
> problem. From what you've shown, one error is that you shouldn't have to
> GetOutput() from a vtkPolyData.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140917/5d60367a/attachment.html>


More information about the vtkusers mailing list