Hey all,<br><br> 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:<br> <br> //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<br>
Sum[3] = 0;<br> Average[3] = 0;<br> Sum[0] += Angle->GetValue(i + (5*n) );<br> Sum[1] += EdgeLength->GetValue( i + (5*n) );<br> Sum[2] += EdgeLength_Horizontal->GetValue( i + (5*n) );<br>
Sum[3] += EdgeLength_Vertical->GetValue( i + (5*n ) );<br><br> //Once the Sum array is filled with data and the for loops are closed, this bit of code is enabled<br> std::cout << "Average Angle: " << Sum[0] / <br>
(Output->GetNumberOfPoints() * 5) << endl <br> << "Average Edge Length: " << Sum[1] /<br> ( Output->GetNumberOfPoints() * 5 ) << endl<br>
<< "Average Horizontal Component of Edge Length: " << Sum[2] /<br> ( Output->GetNumberOfPoints() * 5 ) << endl<br> << "Average Vertical Component of Edge Length: " << Sum[3] /<br>
( Output->GetNumberOfPoints() * 5 ) << endl << endl;<br><br>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:<br>
<br> vtkSmartPointer<vtkFieldData> Field1 =<br> vtkSmartPointer<vtkFieldData>::New();<br> vtkSmartPointer<vtkFieldData> Field2 =<br> vtkSmartPointer<vtkFieldData>::New();<br> vtkSmartPointer<vtkFieldData> Field3 =<br>
vtkSmartPointer<vtkFieldData>::New();<br> vtkSmartPointer<vtkFieldData> Field4 =<br> vtkSmartPointer<vtkFieldData>::New();<br> Field1->AddArray( AngleDecimated );<br> Field2->AddArray( EdgeLengthDecimated );<br>
Field3->AddArray( EdgeLengthHDecimated );<br> Field4->AddArray( EdgeLengthVDecimated );<br> <br> vtkSmartPointer<vtkDataObject> DataObject1 = <br> vtkSmartPointer<vtkDataObject>::New();<br>
vtkSmartPointer<vtkDataObject> DataObject2 = <br> vtkSmartPointer<vtkDataObject>::New();<br> vtkSmartPointer<vtkDataObject> DataObject3 = <br> vtkSmartPointer<vtkDataObject>::New();<br>
vtkSmartPointer<vtkDataObject> DataObject4 = <br> vtkSmartPointer<vtkDataObject>::New();<br> DataObject1->SetFieldData( Field1 );<br> DataObject2->SetFieldData( Field2 );<br> DataObject3->SetFieldData( Field3 );<br>
DataObject4->SetFieldData( Field4 );<br><br> vtkSmartPointer<vtkXYPlotActor> Plot1 =<br> vtkSmartPointer<vtkXYPlotActor>::New();<br> vtkSmartPointer<vtkXYPlotActor> Plot2 =<br> vtkSmartPointer<vtkXYPlotActor>::New();<br>
vtkSmartPointer<vtkXYPlotActor> Plot3 =<br> vtkSmartPointer<vtkXYPlotActor>::New();<br> vtkSmartPointer<vtkXYPlotActor> Plot4 =<br> vtkSmartPointer<vtkXYPlotActor>::New();<br> Plot1->ExchangeAxesOff();<br>
Plot1->SetLabelFormat( "%g" );<br> Plot1->SetXTitle( "Id Number" );<br> Plot1->SetYTitle( "Angle" );<br> Plot1->SetXValuesToIndex();<br> Plot1->AddDataObjectInput( DataObject1 );<br>
Plot1->SetPlotColor(0,1,1,1);<br> Plot2->ExchangeAxesOff();<br> Plot2->SetLabelFormat( "%g" );<br> Plot2->SetXTitle( "Id Number" );<br> Plot2->SetYTitle( "Edge Length" );<br>
Plot2->SetXValuesToIndex();<br> Plot2->AddDataObjectInput( DataObject2 );<br> Plot2->SetPlotColor(0,1,1,1);<br> Plot3->ExchangeAxesOff();<br> Plot3->SetLabelFormat( "%g" );<br>
Plot3->SetXTitle( "Id Number" );<br> Plot3->SetYTitle( "H. Compon." );<br> Plot3->SetXValuesToIndex();<br> Plot3->AddDataObjectInput( DataObject3 );<br> Plot3->SetPlotColor(0,1,1,1);<br>
Plot4->ExchangeAxesOff();<br> Plot4->SetLabelFormat( "%g" );<br> Plot4->SetXTitle( "Id Number" );<br> Plot4->SetYTitle( "V. Compon" );<br> Plot4->SetXValuesToIndex();<br>
Plot4->AddDataObjectInput( DataObject4 );<br> Plot4->SetPlotColor(0,1,1,1);<br> <br> double UpperLeftViewport[4] = { 0.0,0.5,0.5,1.0 };<br> double UpperRightViewport[4] = { 0.5,0.5,1.0,1.0 };<br>
double LowerLeftViewport[4] = { 0.0,0.0,0.5,0.5 };<br> double LowerRightViewport[4] = { 0.5,0.0,1.0,0.5 };<br> <br> // Visualize the histogram(s)<br> vtkSmartPointer<vtkRenderer> UpperLeftRenderer = <br>
vtkSmartPointer<vtkRenderer>::New();<br> vtkSmartPointer<vtkRenderer> UpperRightRenderer = <br> vtkSmartPointer<vtkRenderer>::New();<br> vtkSmartPointer<vtkRenderer> LowerLeftRenderer = <br>
vtkSmartPointer<vtkRenderer>::New();<br> vtkSmartPointer<vtkRenderer> LowerRightRenderer = <br> vtkSmartPointer<vtkRenderer>::New();<br> UpperLeftRenderer->AddActor( Plot1 );<br>
UpperLeftRenderer->SetViewport( UpperLeftViewport );<br> UpperLeftRenderer->SetBackground( 0.1,0.2,0.3 );<br> UpperLeftRenderer->ResetCamera();<br> UpperRightRenderer->AddActor( Plot2 );<br>
UpperRightRenderer->SetViewport( UpperRightViewport );<br> UpperRightRenderer->SetBackground( 0.1,0.2,0.3 );<br> UpperRightRenderer->ResetCamera();<br> LowerLeftRenderer->AddActor( Plot3 );<br>
LowerLeftRenderer->SetViewport( LowerLeftViewport );<br> LowerLeftRenderer->SetBackground( 0.1,0.2,0.3 );<br> LowerLeftRenderer->ResetCamera();<br> LowerRightRenderer->AddActor( Plot1 );<br>
LowerRightRenderer->SetViewport( LowerRightViewport );<br> LowerRightRenderer->SetBackground( 0.1,0.2,0.3 );<br> LowerRightRenderer->ResetCamera();<br> <br> vtkSmartPointer<vtkRenderWindow> renderWindow = <br>
vtkSmartPointer<vtkRenderWindow>::New();<br> renderWindow->AddRenderer( UpperLeftRenderer );<br> renderWindow->AddRenderer( UpperRightRenderer );<br> renderWindow->AddRenderer( LowerLeftRenderer );<br>
renderWindow->AddRenderer( LowerRightRenderer );<br> renderWindow->SetSize( 800,600 );<br> <br> vtkSmartPointer<vtkRenderWindowInteractor> interactor =<br> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
interactor->SetRenderWindow( renderWindow );<br> <br> // Initialize the event loop and then start it<br> interactor->Initialize();<br> interactor->Start();<br><br><br>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 :<br>
<br>Average Angle: 0.646263<br>Average Edge Length: 0.525874<br>Average Horizontal Component of Edge Length: 0.400365<br>Average Vertical Component of Edge Length: 3.83892e-05<br><br><br>and here are the values when I uncomment out the above section of code:<br>
<br>Average Angle: -8.68697e+24<br>Average Edge Length: 0.525874<br>Average Horizontal Component of Edge Length: -nan<br>Average Vertical Component of Edge Length: 3.83892e-05<br><br><br>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.<br>
Thanks,<br>Luke H<br>