[vtkusers] filling a vtkFloatArray ... first element?

jbouffar julian.m.bouffard at erdc.dren.mil
Thu May 19 12:26:02 EDT 2016


Hello,

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.


More information about the vtkusers mailing list