View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001153VTK(No Category)public2004-09-10 06:292016-08-12 09:54
Reporterpra 
Assigned ToBerk Geveci 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001153: Bug in SetActiveAttribute?
DescriptionDear,

There seems to be a bug in vtkDataSetAttributes when using SetActiveAttribute (int index, int attributeType).


The following works fine (using a name):
  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    sprintf(name, "PCTEST%i", i);

    pPolyData->GetPointData()->SetActiveAttribute(name, vtkDataSetAttributes::VECTORS);

double* d = pPolyData->GetPointData()->GetVectors()->GetTuple3(1);

}

when using a number instead of a name:

  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    sprintf(name, "PCTEST%i", i);

    pPolyData->GetPointData()->SetActiveAttribute(i, vtkDataSetAttributes::VECTORS);

double* d = pPolyData->GetPointData()->GetVectors()->GetTuple3(1);

}

it doesn’t change the active vectorfield.

Best wishes,
Per

PS: Complete c++ test code:

// testAddArray.cpp : Defines the entry point for the console application.
//


#include <iostream>
#include <tchar.h>


#include <vtkPolyData.h>
#include <vtkDataSetAttributes.h>
#include <vtkAssignAttribute.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>


#pragma comment(lib, "vtkHybrid.lib")
#pragma comment(lib, "vtkIO.lib")
#pragma comment(lib, "vtkGraphics.lib")
#pragma comment(lib, "vtkFiltering.lib")
#pragma comment(lib, "vtkCommon.lib")


using namespace std;

#include <vector>
void main(int argc, _TCHAR* argv[])
{

  vtkPolyDataReader *pReader = vtkPolyDataReader::New();
  vtkPolyData *pPolyData = vtkPolyData::New();
  vtkPolyDataWriter *pWriter = vtkPolyDataWriter::New();
  vector<vtkDataArray* > vec_DataArray;
  int i;
  char name[255];

  pReader->SetFileName("fran_cut.vtk"); // 'fran_cut.vtk' from the vtk test set
  pReader->Update();
  pPolyData->DeepCopy(pReader->GetOutput());

  cerr << "pPolyData->GetNumberOfPoints() = " << pPolyData->GetNumberOfPoints() << "\n";

  // Make vector field
  vec_DataArray.resize(3);
  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    vec_DataArray[i] = vtkDoubleArray::New();

    vtkDataArray* v = vec_DataArray[i];

    sprintf(name, "PCTEST%i", i);
    v->SetName(name);
    v->SetNumberOfComponents(3);
    v->SetNumberOfTuples(pPolyData->GetNumberOfPoints());

    for(int j = 0; j < v->GetNumberOfTuples(); ++j)
    {
      const double d = i + j / 1.e4;
      v->SetTuple3(j, d, d, d);
    }
  }

  // Add vectors to dataset
  //
  // 11111111111111111
  //
  cerr << "..........1st test...........\n";

  cerr << " Shows that many field sets may be added to a dataset.\n";

  pPolyData->DeepCopy(pReader->GetOutput());

  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    pPolyData->GetPointData()->AddArray(vec_DataArray[i]);
  }

  pWriter->SetInput(pPolyData);
  pWriter->SetFileName("fran_cut_with_test_vectors_1.vtk");
  pWriter->Write(); // Write data set with 'FieldData'

  //
  // 22222222222222222
  //
  cerr << "..........2nd test...........\n";

  cerr << " Shows that it's not possible to add more the one vector-attribute to a dataset.\n";

  pPolyData->DeepCopy(pReader->GetOutput());

  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    pPolyData->GetPointData()->SetVectors(vec_DataArray[i]);
  }

  // check that all vectors are in dataset!
  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    sprintf(name, "PCTEST%i", i);

    pPolyData->GetPointData()->SetActiveVectors(name);

    if (pPolyData->GetPointData()->GetVectors()==NULL)
    {
      cerr << "no vector with name '" << name << "'....continue\n";
      continue;
    }

    double* d = pPolyData->GetPointData()->GetVectors()->GetTuple3(1);
    cerr << name << " "
      << d[0] << " "
      << d[1] << " "
      << d[2] << " "
      << "\n";
  }

  pWriter->SetInput(pPolyData);
  pWriter->SetFileName("fran_cut_with_test_vectors_2.vtk");
  pWriter->Write(); // Write data set with 'FieldData'

  //
  // 33333333333333333
  //
  cerr << "..........3rd test...........\n";

  cerr << " Shows how easy field data may be converted/assigned as vector-attribute to the dataset.\n";


  pReader->SetFileName("fran_cut_with_test_vectors_1.vtk");
  pReader->Update();

  pPolyData->DeepCopy(pReader->GetOutput());

  cerr << (pPolyData->GetPointData()->GetVectors() != NULL) << " - should be zero as not vector field is assigned/present\n";

  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    sprintf(name, "PCTEST%i", i);

    pPolyData->GetPointData()->SetActiveAttribute(name, vtkDataSetAttributes::VECTORS);

    double* d = pPolyData->GetPointData()->GetVectors()->GetTuple3(1);
    cerr << name << " "
      << d[0] << " "
      << d[1] << " "
      << d[2] << " "
      << "\n";

    cerr << "just to show that the number also can be used. BUT IT DOESN'T WORK\n";
    pPolyData->GetPointData()->SetActiveAttribute((i+1)%vec_DataArray.size(), vtkDataSetAttributes::VECTORS); // just to show that the number also can be used!

    d = pPolyData->GetPointData()->GetVectors()->GetTuple3(1);
    cerr << (i+1)%vec_DataArray.size() << " "
      << d[0] << " "
      << d[1] << " "
      << d[2] << " "
      << "\n\n";
  }

  //
  // 44444444444444444
  //
  cerr << "..........4th test...........\n";

  cerr << " Shows the same as 3rd test but uses vtkAssignAttribute.\n";

  vtkAssignAttribute* aa = vtkAssignAttribute::New();
  aa->SetInput(pReader->GetOutput());

  for(i = 0; i < vec_DataArray.size(); ++i)
  {
    sprintf(name, "PCTEST%i", i);

    aa->Assign(name, vtkDataSetAttributes::VECTORS,
      vtkAssignAttribute::POINT_DATA); // POINT_DATA: Attribute found in POINT_DATA not cell data
    aa->Update();

    try
    {
      double* d = aa->GetOutput()->GetPointData()->GetVectors()->GetTuple3(1);
      cerr << name << " "
        << d[0] << " "
        << d[1] << " "
        << d[2] << " "
        << "\n";
    }
    catch (...) {cerr << "exception!!!\n";}
  }


#define VTKRELEASE(x) x->Delete()

  VTKRELEASE(pReader);
  VTKRELEASE(pPolyData);
  VTKRELEASE(pWriter);

  for(i = 0; i < vec_DataArray.size(); ++i) VTKRELEASE(vec_DataArray[i]);


    return;
}
TagsNo tags attached.
Project
Type
Attached Files

 Relationships

  Notes
(0036751)
Kitware Robot (administrator)
2016-08-12 09:54

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2011-06-16 13:11 Zack Galbreath Category => (No Category)
2016-08-12 09:54 Kitware Robot Note Added: 0036751
2016-08-12 09:54 Kitware Robot Status expired => closed
2016-08-12 09:54 Kitware Robot Resolution open => moved


Copyright © 2000 - 2018 MantisBT Team