[vtkusers] vtkrenderer causing other sections of code to break???

Luke Hetrick lhetrick at nnu.edu
Fri Jul 20 15:25:32 EDT 2012


Hey all,

   So I am experiencing an interesting error that I can not figure out. I
am storing some data in some arrays and I am then printing out the average
of those arrays by the following bit of code:

       //this Sum array is in-bedded in a set of for loops where the
iterators are i and n to fill it full of data
       Sum[3] = 0;
       Average[3] = 0;
       Sum[0] += Angle->GetValue(i + (5*n) );
       Sum[1] += EdgeLength->GetValue( i + (5*n) );
       Sum[2] += EdgeLength_Horizontal->GetValue( i + (5*n) );
       Sum[3] += EdgeLength_Vertical->GetValue( i + (5*n ) );

      //Once the Sum array is filled with data and the for loops are
closed, this bit of code is enabled
      std::cout << "Average Angle: " << Sum[0] /
                         (Output->GetNumberOfPoints() * 5) << endl
                    << "Average Edge Length: " <<  Sum[1] /
                         ( Output->GetNumberOfPoints() * 5 ) << endl
                    << "Average Horizontal Component of Edge Length: " <<
Sum[2] /
                         ( Output->GetNumberOfPoints() * 5 ) << endl
                    << "Average Vertical Component of Edge Length: " <<
Sum[3] /
                         ( Output->GetNumberOfPoints() * 5 ) << endl <<
endl;

What I am expericing is that when I add a renderer for a completely
different set of arrays other than these Sum and Average arrays, the
average values that are printed out onto my screen are changed to
ridiculous numbers. When I uncomment out this bit of code, the average
values that get printed out change from the values they should be to e^23
and -nan on two of the average values. Here is the bit of code that is
causing me problems:

      vtkSmartPointer<vtkFieldData> Field1 =
    vtkSmartPointer<vtkFieldData>::New();
      vtkSmartPointer<vtkFieldData> Field2 =
    vtkSmartPointer<vtkFieldData>::New();
      vtkSmartPointer<vtkFieldData> Field3 =
    vtkSmartPointer<vtkFieldData>::New();
      vtkSmartPointer<vtkFieldData> Field4 =
    vtkSmartPointer<vtkFieldData>::New();
      Field1->AddArray( AngleDecimated );
      Field2->AddArray( EdgeLengthDecimated );
      Field3->AddArray( EdgeLengthHDecimated );
      Field4->AddArray( EdgeLengthVDecimated );

      vtkSmartPointer<vtkDataObject> DataObject1 =
        vtkSmartPointer<vtkDataObject>::New();
      vtkSmartPointer<vtkDataObject> DataObject2 =
        vtkSmartPointer<vtkDataObject>::New();
      vtkSmartPointer<vtkDataObject> DataObject3 =
        vtkSmartPointer<vtkDataObject>::New();
      vtkSmartPointer<vtkDataObject> DataObject4 =
        vtkSmartPointer<vtkDataObject>::New();
      DataObject1->SetFieldData( Field1 );
      DataObject2->SetFieldData( Field2 );
      DataObject3->SetFieldData( Field3 );
      DataObject4->SetFieldData( Field4 );

      vtkSmartPointer<vtkXYPlotActor> Plot1 =
    vtkSmartPointer<vtkXYPlotActor>::New();
      vtkSmartPointer<vtkXYPlotActor> Plot2 =
    vtkSmartPointer<vtkXYPlotActor>::New();
      vtkSmartPointer<vtkXYPlotActor> Plot3 =
    vtkSmartPointer<vtkXYPlotActor>::New();
      vtkSmartPointer<vtkXYPlotActor> Plot4 =
    vtkSmartPointer<vtkXYPlotActor>::New();
       Plot1->ExchangeAxesOff();
       Plot1->SetLabelFormat( "%g" );
       Plot1->SetXTitle( "Id Number" );
       Plot1->SetYTitle( "Angle" );
       Plot1->SetXValuesToIndex();
       Plot1->AddDataObjectInput( DataObject1 );
       Plot1->SetPlotColor(0,1,1,1);
       Plot2->ExchangeAxesOff();
       Plot2->SetLabelFormat( "%g" );
       Plot2->SetXTitle( "Id Number" );
       Plot2->SetYTitle( "Edge Length" );
       Plot2->SetXValuesToIndex();
       Plot2->AddDataObjectInput( DataObject2 );
       Plot2->SetPlotColor(0,1,1,1);
       Plot3->ExchangeAxesOff();
       Plot3->SetLabelFormat( "%g" );
       Plot3->SetXTitle( "Id Number" );
       Plot3->SetYTitle( "H. Compon." );
       Plot3->SetXValuesToIndex();
       Plot3->AddDataObjectInput( DataObject3 );
       Plot3->SetPlotColor(0,1,1,1);
       Plot4->ExchangeAxesOff();
       Plot4->SetLabelFormat( "%g" );
       Plot4->SetXTitle( "Id Number" );
       Plot4->SetYTitle( "V. Compon" );
       Plot4->SetXValuesToIndex();
       Plot4->AddDataObjectInput( DataObject4 );
       Plot4->SetPlotColor(0,1,1,1);

       double UpperLeftViewport[4] = { 0.0,0.5,0.5,1.0 };
       double UpperRightViewport[4] = { 0.5,0.5,1.0,1.0 };
       double LowerLeftViewport[4] = { 0.0,0.0,0.5,0.5 };
       double LowerRightViewport[4] = { 0.5,0.0,1.0,0.5 };

      // Visualize the histogram(s)
      vtkSmartPointer<vtkRenderer> UpperLeftRenderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderer> UpperRightRenderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderer> LowerLeftRenderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderer> LowerRightRenderer =
        vtkSmartPointer<vtkRenderer>::New();
      UpperLeftRenderer->AddActor( Plot1 );
      UpperLeftRenderer->SetViewport( UpperLeftViewport );
      UpperLeftRenderer->SetBackground( 0.1,0.2,0.3 );
      UpperLeftRenderer->ResetCamera();
      UpperRightRenderer->AddActor( Plot2 );
      UpperRightRenderer->SetViewport( UpperRightViewport );
      UpperRightRenderer->SetBackground( 0.1,0.2,0.3 );
      UpperRightRenderer->ResetCamera();
      LowerLeftRenderer->AddActor( Plot3 );
      LowerLeftRenderer->SetViewport( LowerLeftViewport );
      LowerLeftRenderer->SetBackground( 0.1,0.2,0.3 );
      LowerLeftRenderer->ResetCamera();
      LowerRightRenderer->AddActor( Plot1 );
      LowerRightRenderer->SetViewport( LowerRightViewport );
      LowerRightRenderer->SetBackground( 0.1,0.2,0.3 );
      LowerRightRenderer->ResetCamera();

      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer( UpperLeftRenderer );
      renderWindow->AddRenderer( UpperRightRenderer );
      renderWindow->AddRenderer( LowerLeftRenderer );
      renderWindow->AddRenderer( LowerRightRenderer );
      renderWindow->SetSize( 800,600 );

      vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      interactor->SetRenderWindow( renderWindow );

      // Initialize the event loop and then start it
      interactor->Initialize();
      interactor->Start();


So nowhere in this bit of code do I do any operations to the Sum or Average
arrays but yet somehow this bit of code can alter the average values
printed out? Another odd thing is that the Average and Sum arrays come
before the whole rendering process I mentioned. So by my understanding is
that anything behind where I print out the average values should not have
an effect on the values but yet somehow it is...here are the values with
the rendering code I have shown above commented out :

Average Angle: 0.646263
Average Edge Length: 0.525874
Average Horizontal Component of Edge Length: 0.400365
Average Vertical Component of Edge Length: 3.83892e-05


and here are the values when I uncomment out the above section of code:

Average Angle: -8.68697e+24
Average Edge Length: 0.525874
Average Horizontal Component of Edge Length: -nan
Average Vertical Component of Edge Length: 3.83892e-05


I am thinking that the /vtkXYPlotActor might have a bug in it like many of
the other chart and plotting actors that is causing this but that is just a
gut feeling. If anyone has any thoughts on this matter, please share them
with me and the community.
Thanks,
Luke H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120720/2b2673c0/attachment.htm>


More information about the vtkusers mailing list