[vtkusers] filling a vtkFloatArray ... first element?
David Lonie
david.lonie at kitware.com
Thu May 19 13:45:29 EDT 2016
Both arguments to GetComponent are zero based -- so to get the first
component of the first tuple, you should call GetComponent(0, 0), not
GetComponent(0, 1).
HTH,
Dave
On Thu, May 19, 2016 at 12:26 PM, jbouffar <julian.m.bouffard at erdc.dren.mil>
wrote:
> I have a strange question. It seems the first element I put into a
> vtkFloatArray is missing, so that if I construct a new floatArray element
> by
> element from some other arrays, they are out of sync by one element. I
> have
> written some code in c++ to illustrate this (below). Even weirder (to me)
> it seems I can access the [-1] component, and it works! What is going on
> here? I have tried also using SetNumberOfTuples and SetTuple, but this
> doesn't even work. This is VTK 6.3.
>
> int main(int argc, char** argv){
>
> vtkSmartPointer<vtkFloatArray> flame =
> vtkSmartPointer<vtkFloatArray>::New();
> flame->SetNumberOfComponents(1);
>
> for(int i = 0; i < 10; i++){
> flame->InsertNextTuple1(i);
> vtkIdType id = i;
> cout << flame->GetComponent(id,1) << ", " <<
> flame->GetComponent(id-1,1)
> << endl;
> }
>
> cout << "nTuples = " << flame->GetNumberOfTuples() << endl;
>
> cout << "Contents of flame: " << endl;
> for(int i = 0; i < flame->GetNumberOfTuples(); i++){
> vtkIdType id = i;
> cout << "i = " << i << ", flame[" << i << "] = " <<
> flame->GetComponent(id,1) << endl;
> }
>
> //Okay, maybe if we use SetNumberOfTuples and SetTuple1 it will work.
> Nope!
> vtkIdType id = 0;
> flame->SetTuple1(id, 99);
> float retrieved = flame->GetComponent(id,1);
> cout << "retrieved = " << retrieved << endl;
> retrieved = flame->GetComponent(-1,1);
> cout << "retrieved = " << retrieved << endl;
>
> return 0;
> }
>
> Output:
>
> 4.58589e-41, 0
> 2.13737e+11, 1
> 4.58589e-41, 2
> 0, 3
> 0, 4
> 1.99685e-42, 5
> 0, 6
> 2.13737e+11, 7
> 4.58589e-41, 8
> 1.97443e-42, 9
> nTuples = 10
> Contents of flame:
> i = 0, flame[0] = 1
> i = 1, flame[1] = 2
> i = 2, flame[2] = 3
> i = 3, flame[3] = 4
> i = 4, flame[4] = 5
> i = 5, flame[5] = 6
> i = 6, flame[6] = 7
> i = 7, flame[7] = 8
> i = 8, flame[8] = 9
> i = 9, flame[9] = 1.97443e-42
> retrieved = 1
> retrieved = 99
>
>
>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/filling-a-vtkFloatArray-first-element-tp5738146.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160519/dfe7e1d6/attachment.html>
More information about the vtkusers
mailing list