[vtkusers] GetEdgeData->Reset() breaks EdgeData

Aashish Chaudhary aashish.chaudhary at kitware.com
Tue Mar 30 17:33:14 EDT 2010


Hi David,

As I recall

Your AddArray() wont do anything.. because its the same array as before and
Reset does do much other than setting the MaxId to -1 (which means that you
will get NumberOfTuples to 0 when you query later)

vtkIdType GetNumberOfTuples()
    {return (this->MaxId + 1)/this->NumberOfComponents;}

HTH,
Aashish



On Tue, Mar 30, 2010 at 4:09 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> It seems that after I call Reset(), I cannot add anything to the
> EdgeData. The following examples shows that I add a length 2 weight
> array to the graph, prove that it was added properly, Reset() the
> EdgeData, then try to add the weight array again. This time, the graph
> contains 0 weights after adding the weights array. The only reason I
> started calling Reset is because in my filter the number of weights is
> being reported incorrectly, I believe because it used to have a
> "Weights" array, and I am trying to replace it with a new one.
>
> Any thoughts?
>
> #include <vtkSmartPointer.h>
> #include <vtkDoubleArray.h>
> #include <vtkDataSetAttributes.h>
> #include <vtkMutableDirectedGraph.h>
>
> int main(int argc, char *argv[])
> {
>  vtkSmartPointer<vtkMutableDirectedGraph> dg =
>      vtkSmartPointer<vtkMutableDirectedGraph>::New();
>
>  vtkIdType v1 = dg->AddVertex();
>  vtkIdType v2 = dg->AddChild(v1);
>
>  vtkSmartPointer<vtkDoubleArray> weights =
>      vtkSmartPointer<vtkDoubleArray>::New();
>  weights->SetNumberOfComponents(1);
>  weights->SetName("Weights");
>
>  //set the edge weights
>  weights->InsertNextValue(1.0);
>  weights->InsertNextValue(2.0);
>
>  cout << "Number of weights in array: " <<
> weights->GetNumberOfTuples() << endl;
>
>  //add the edge weight array to the graph
>  dg->GetEdgeData()->AddArray(weights);
>
>  cout << "Number of weights added: " <<
>
> vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
> << endl;
>
>  dg->GetEdgeData()->Reset();
>
>  cout << "Number of weights: " <<
>
> vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
> << endl;
>
>  dg->GetEdgeData()->AddArray(weights);
>
>  cout << "Number of weights added: " <<
>
> vtkDoubleArray::SafeDownCast(dg->GetEdgeData()->GetArray("Weights"))->GetNumberOfTuples()
> << endl;
>
>  return EXIT_SUCCESS;
> }
>
> Thanks,
>
> David
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100330/f5fac260/attachment.htm>


More information about the vtkusers mailing list