[vtkusers] Setting multiple scalars to a dataset

Steve Boyd boyd at biomed.ee.ethz.ch
Mon Jun 3 10:35:15 EDT 2002


KRS,

Here's how I used multiple scalar arrays in my reader class in case it's
of any help.  I haven't tried it yet, but I think in order to switch
between the added arrays I type something of the sort:
myclass->GetPointData()->SetActiveAttribute("VTK_STRESS_VM",vtkDataSetAttributes::SCALARS);

Hope this helps (and is correct!).

Sincerely,

Steve


    // Declare some variables
    float   f7tuple[7];
    int     i, j;
    vtkFloatArray *stressesAndStrains[7];

    // Initialize and set the array names
    for (i=0; i<7; i++) stressesAndStrains[i] = vtkFloatArray::New();
    for (i=0; i<7; i++) stressesAndStrains[i]->SetNumberOfComponents(1);
    for (i=0; i<7; i++)
stressesAndStrains[i]->SetNumberOfTuples(nCells);
    stressesAndStrains[0]->SetName("VTK_STRESS_11");
    stressesAndStrains[1]->SetName("VTK_STRESS_22");
    stressesAndStrains[2]->SetName("VTK_STRESS_33");
    stressesAndStrains[3]->SetName("VTK_STRESS_12");
    stressesAndStrains[4]->SetName("VTK_STRESS_23");
    stressesAndStrains[5]->SetName("VTK_STRESS_31");
    stressesAndStrains[6]->SetName("VTK_STRESS_VM");

    // Read the data from file and set the array data
    for (i=0; i<nCells; i++) {
      this->ReadLine(line);
      sscanf(line,"%*d %*d %f %f %f %f %f %f %f %f %f",
       
f7tuple,f7tuple+1,f7tuple+2,f7tuple+3,f7tuple+4,f7tuple+5,f7tuple+6);
      for (j=0; j<7; j++)
        stressesAndStrains[j]->SetTuple(i,f7tuple+j);
    }

    // Set the active array, indexed by my class variable
this->ActiveScalar, to the cell data
    if ( stressesAndStrains[this->ActiveScalar] != NULL ) {
     
output->GetCellData()->SetScalars(stressesAndStrains[this->ActiveScalar]);
    } else {
      vtkWarningMacro(<<"\n  Scalar components were not successfully
added.");
    }

    // Set all of the arrays (inactive and active) to the object for
later use (????)
    for (i=0; i<7; i++)
      if (stressesAndStrains[i] != NULL) 
        output->GetCellData()->AddArray(stressesAndStrains[i]);

-- 
Steven Boyd, PhD

Institute for Biomedical Engineering
ETH and University Zuerich
Moussonstrasse 18
8044 Zuerich, Switzerland

tel. +41.1.632.4591  fax. +41.1.632.1214  boyd at biomed.ee.ethz.ch
-------------------------------------------------------------------



More information about the vtkusers mailing list