diff --git a/Charts/Core/Testing/Cxx/TestAreaPlot.cxx b/Charts/Core/Testing/Cxx/TestAreaPlot.cxx index 0f5b4e88be6..b2337f69c7f 100644 --- a/Charts/Core/Testing/Cxx/TestAreaPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestAreaPlot.cxx @@ -68,7 +68,7 @@ int TestAreaPlot( int, char * [] ) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc + 0.01); table->SetValue(i, 1, cos(i * inc) + 0.01); table->SetValue(i, 2, sin(i * inc) + 0.01); @@ -77,7 +77,7 @@ int TestAreaPlot( int, char * [] ) table->SetValue(i, 5, 1.0); validMask->SetValue(i, (i > 30 && i < 40) ? 0 : 1); - } + } // Add multiple line plots, setting the colors etc vtkPlotArea* area = vtkPlotArea::SafeDownCast(chart->AddPlot(vtkChart::AREA)); diff --git a/Charts/Core/Testing/Cxx/TestAxes.cxx b/Charts/Core/Testing/Cxx/TestAxes.cxx index 94695a2eaff..40d3261bef4 100644 --- a/Charts/Core/Testing/Cxx/TestAxes.cxx +++ b/Charts/Core/Testing/Cxx/TestAxes.cxx @@ -50,7 +50,7 @@ int TestAxes(int , char * []) std::vector > axesVertical(4); for (size_t i = 0; i < axesVertical.size(); ++i) - { + { axesVertical[i] = vtkSmartPointer::New(); vtkAxis *axis = axesVertical[i].GetPointer(); axis->SetPoint1(vtkVector2f(i * 69 + 30, 10)); @@ -60,7 +60,7 @@ int TestAxes(int , char * []) axis->SetRange(-1, 50); view->GetScene()->AddItem(axis); - } + } // Exercise some of the API in the axis API. axesVertical[0]->AutoScale(); @@ -85,15 +85,15 @@ int TestAxes(int , char * []) axesVertical[3]->AutoScale(); for (size_t i = 0; i < axesVertical.size(); ++i) - { + { axesVertical[i]->Update(); - } + } // Let's create a few axes, and place them on the scene. std::vector > axesHorizontal(6); for (size_t i = 0; i < axesHorizontal.size(); ++i) - { + { axesHorizontal[i] = vtkSmartPointer::New(); vtkAxis *axis = axesHorizontal[i].GetPointer(); axis->SetPoint1(vtkVector2f(310, i * 50 + 30)); @@ -103,7 +103,7 @@ int TestAxes(int , char * []) view->GetScene()->AddItem(axis); axis->Update(); - } + } // Now to test some of the API in the horizontal axes. axesHorizontal[0]->LogScaleOn(); // LogScaleActive=false because min*max<0 @@ -112,10 +112,10 @@ int TestAxes(int , char * []) axesHorizontal[0]->GetRange(range); if (!axesHorizontal[0]->GetLogScaleActive() || fabs(range[0]) > 1e-8 || fabs(range[1] - 2.) > 1e-8) - { + { cerr << "ERROR: did not transition to log scaling when range changed.\n"; status = EXIT_FAILURE; - } + } // Now change the axis limits in log-space... axesHorizontal[0]->SetMinimumLimit(-1.); axesHorizontal[0]->SetMaximumLimit(3.); @@ -123,19 +123,19 @@ int TestAxes(int , char * []) if ( fabs(axesHorizontal[0]->GetUnscaledMinimumLimit()-0.1) > 1e-8 || fabs(axesHorizontal[0]->GetUnscaledMaximumLimit()-1000.0) > 1e-8) - { + { cerr << "ERROR: did not update unscaled limits when scaled limits changed.\n"; status = EXIT_FAILURE; - } + } axesHorizontal[0]->LogScaleOff(); if (axesHorizontal[0]->GetLogScaleActive() || -axesHorizontal[0]->GetMinimumLimit() == axesHorizontal[0]->GetMaximumLimit()) - { + { cerr << "ERROR: did not transition from log scaling or reset limits.\n"; status = EXIT_FAILURE; - } + } axesHorizontal[0]->AutoScale(); axesHorizontal[0]->SetRange(20, 60); // restore range so rest of test can proceed @@ -158,9 +158,9 @@ int TestAxes(int , char * []) axesHorizontal[5]->SetPosition(vtkAxis::BOTTOM); for (size_t i = 0; i < axesHorizontal.size(); ++i) - { + { axesHorizontal[i]->Update(); - } + } // Test LogScale and UnscaledRange methods vtkNew logAxis; @@ -172,29 +172,29 @@ int TestAxes(int , char * []) logAxis->GetUnscaledRange(NULL); // Insure NULL pointers are ignored. logAxis->GetUnscaledRange(logRange); if ((logRange[0] != plainRange[0]) || (logRange[1] != plainRange[1])) - { + { vtkGenericWarningMacro( << "Error: expected unscaled range to be unchanged but got [" << logRange[0] << ", " << logRange[1] << "]."); - } + } logAxis->GetRange(logRange); if ( (fabs((pow(10., logRange[0]) - plainRange[0])) > 1e-6) || (fabs((pow(10., logRange[1]) - plainRange[1])) > 1e-6)) - { + { vtkGenericWarningMacro( << "Error: expected scaled range to be [-1, 3] but got [" << logRange[0] << ", " << logRange[1] << "]."); - } + } if ( (logAxis->GetMinimum() != logRange[0]) || (logAxis->GetMaximum() != logRange[1]) || (logAxis->GetUnscaledMinimum() != plainRange[0]) || (logAxis->GetUnscaledMaximum() != plainRange[1])) - { + { vtkGenericWarningMacro( "Error: returned ranges do not match returned min/max."); - } + } logAxis->SetMinimum(logRange[0]); logAxis->SetMaximum(logRange[1]); logAxis->Update(); diff --git a/Charts/Core/Testing/Cxx/TestBagPlot.cxx b/Charts/Core/Testing/Cxx/TestBagPlot.cxx index cc61c62d246..97502b7a2de 100644 --- a/Charts/Core/Testing/Cxx/TestBagPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestBagPlot.cxx @@ -80,16 +80,16 @@ int TestBagPlot(int, char * []) // Fill the table for (int j = 0; j < numDataJ; ++j) - { + { for (int i = 0; i < numDataI; ++i) - { + { table->SetValue(i + j * numDataI, 0, i); //X table->SetValue(i + j * numDataI, 1, j); //Y double d = densities[i + j * numDataI]; table->SetValue(i + j * numDataI, 2, d); // Density - } - cout << endl; } + cout << endl; + } vtkNew bagPlot; chart->AddPlot(bagPlot.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestBarGraph.cxx b/Charts/Core/Testing/Cxx/TestBarGraph.cxx index 8c79123fc3d..c1cfcf4911f 100644 --- a/Charts/Core/Testing/Cxx/TestBarGraph.cxx +++ b/Charts/Core/Testing/Cxx/TestBarGraph.cxx @@ -65,12 +65,12 @@ int TestBarGraph(int , char * []) table->SetNumberOfRows(12); for (int i = 0; i < 12; i++) - { + { table->SetValue(i,0,i+1); table->SetValue(i,1,data_2008[i]); table->SetValue(i,2,data_2009[i]); table->SetValue(i,3,data_2010[i]); - } + } // Add multiple bar plots, setting the colors etc vtkPlot *plot = 0; diff --git a/Charts/Core/Testing/Cxx/TestBarGraphHorizontal.cxx b/Charts/Core/Testing/Cxx/TestBarGraphHorizontal.cxx index 19d6ea38ab4..18ba9ee841e 100644 --- a/Charts/Core/Testing/Cxx/TestBarGraphHorizontal.cxx +++ b/Charts/Core/Testing/Cxx/TestBarGraphHorizontal.cxx @@ -64,12 +64,12 @@ int TestBarGraphHorizontal(int , char * []) table->SetNumberOfRows(12); for (int i = 0; i < 12; i++) - { + { table->SetValue(i,0,i+1); table->SetValue(i,1,data_2008[i]); table->SetValue(i,2,data_2009[i]); table->SetValue(i,3,data_2010[i]); - } + } // Add multiple bar plots, setting the colors etc vtkPlot *plot = 0; diff --git a/Charts/Core/Testing/Cxx/TestBarGraphSelection.cxx b/Charts/Core/Testing/Cxx/TestBarGraphSelection.cxx index 45732dad98d..a759e9993f2 100644 --- a/Charts/Core/Testing/Cxx/TestBarGraphSelection.cxx +++ b/Charts/Core/Testing/Cxx/TestBarGraphSelection.cxx @@ -66,12 +66,12 @@ int TestBarGraphSelection(int , char * []) table->SetNumberOfRows(12); for (int i = 0; i < 12; i++) - { + { table->SetValue(i,0,i+1); table->SetValue(i,1,data_2008[i]); table->SetValue(i,2,data_2009[i]); table->SetValue(i,3,data_2010[i]); - } + } // Build a selection object. vtkNew selection; diff --git a/Charts/Core/Testing/Cxx/TestBoxPlot.cxx b/Charts/Core/Testing/Cxx/TestBoxPlot.cxx index b0257b2d83c..1c67f5db73a 100644 --- a/Charts/Core/Testing/Cxx/TestBoxPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestBoxPlot.cxx @@ -45,26 +45,26 @@ int TestBoxPlot(int , char* []) vtkNew inputBoxPlotTable; for (int i = 0; i < numParam; i++) - { + { char num[10]; sprintf(num, "P%d", i); vtkNew arrIndex; arrIndex->SetName(num); inputBoxPlotTable->AddColumn(arrIndex.GetPointer()); - } + } inputBoxPlotTable->SetNumberOfRows(5); // This scaling parameter can be used to test Y axis positioning const double scale = 1e02; for (int i = 0; i < numParam; i++) - { + { inputBoxPlotTable->SetValue(0, i, (i/2) * scale); //Q0 inputBoxPlotTable->SetValue(1, i, (2*i + 2 - i) * scale); //Q1 inputBoxPlotTable->SetValue(2, i, (2*i + 4) * scale); //Q2 inputBoxPlotTable->SetValue(3, i, (2*i + 7) * scale); //Q3 inputBoxPlotTable->SetValue(4, i, (2*i + 8) * scale); //Q4 - } + } vtkNew lookup; lookup->SetNumberOfColors(5); diff --git a/Charts/Core/Testing/Cxx/TestCategoryLegend.cxx b/Charts/Core/Testing/Cxx/TestCategoryLegend.cxx index 1c2c2a49b0e..0cb1d1257c0 100644 --- a/Charts/Core/Testing/Cxx/TestCategoryLegend.cxx +++ b/Charts/Core/Testing/Cxx/TestCategoryLegend.cxx @@ -39,9 +39,9 @@ int TestCategoryLegend(int argc, char* argv[]) vtkNew lut; for (int i = 0; i < values->GetNumberOfTuples(); ++i) - { + { lut->SetAnnotation(values->GetValue(i), values->GetValue(i).ToString()); - } + } vtkNew colorSeries; colorSeries->SetColorScheme(vtkColorSeries::BREWER_QUALITATIVE_SET3); @@ -66,10 +66,10 @@ int TestCategoryLegend(int argc, char* argv[]) int retVal = vtkRegressionTestImage(contextView->GetRenderWindow()); if (retVal == vtkRegressionTester::DO_INTERACTOR) - { + { contextView->GetRenderWindow()->Render(); contextView->GetInteractor()->Start(); retVal = vtkRegressionTester::PASSED; - } + } return !retVal; } diff --git a/Charts/Core/Testing/Cxx/TestChartDouble.cxx b/Charts/Core/Testing/Cxx/TestChartDouble.cxx index 12c48bd9150..ac6baffbfad 100644 --- a/Charts/Core/Testing/Cxx/TestChartDouble.cxx +++ b/Charts/Core/Testing/Cxx/TestChartDouble.cxx @@ -54,13 +54,13 @@ int TestChartDouble(int, char *[]) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { double x(i * inc + 0.2); table->SetValue(i, 0, x); table->SetValue(i, 1, 1.0e-80 * (cos(x - 1.0) + sin(x - 3.14 / 4.0))); table->SetValue(i, 2, 1.0e-80 * sin(x) * 1e-12); table->SetValue(i, 3, 1.0e-80 * sin(x - 1.0)); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestChartDoubleColors.cxx b/Charts/Core/Testing/Cxx/TestChartDoubleColors.cxx index 29ea6125b53..cfb24cf6c1c 100644 --- a/Charts/Core/Testing/Cxx/TestChartDoubleColors.cxx +++ b/Charts/Core/Testing/Cxx/TestChartDoubleColors.cxx @@ -59,14 +59,14 @@ int TestChartDoubleColors(int, char *[]) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { double x(i * inc + 0.2); table->SetValue(i, 0, x); table->SetValue(i, 1, 1.0e-80 * (cos(x - 1.0) + sin(x - 3.14 / 4.0))); table->SetValue(i, 2, 1.0e-80 * sin(x) * 1e-12); table->SetValue(i, 3, 1.0e-80 * sin(x - 1.0)); table->SetValue(i, 4, cos(i * inc)); - } + } vtkNew lut; lut->SetValueRange(0.0, 1.0); diff --git a/Charts/Core/Testing/Cxx/TestChartMatrix.cxx b/Charts/Core/Testing/Cxx/TestChartMatrix.cxx index 9fb56b7efb1..c27333a61aa 100644 --- a/Charts/Core/Testing/Cxx/TestChartMatrix.cxx +++ b/Charts/Core/Testing/Cxx/TestChartMatrix.cxx @@ -59,13 +59,13 @@ int TestChartMatrix( int, char * [] ) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc)); table->SetValue(i, 2, sin(i * inc)); table->SetValue(i, 3, sin(i * inc) + 0.5); table->SetValue(i, 4, tan(i * inc)); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestChartTileScaling.cxx b/Charts/Core/Testing/Cxx/TestChartTileScaling.cxx index f553bf70e00..b9ff1ffd688 100644 --- a/Charts/Core/Testing/Cxx/TestChartTileScaling.cxx +++ b/Charts/Core/Testing/Cxx/TestChartTileScaling.cxx @@ -65,11 +65,11 @@ int TestChartTileScaling( int, char *[]) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, sin(i * inc) + 0.0); table->SetValue(i, 2, 1.0); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestChartUnicode.cxx b/Charts/Core/Testing/Cxx/TestChartUnicode.cxx index df9543e3dff..dbac892f84b 100644 --- a/Charts/Core/Testing/Cxx/TestChartUnicode.cxx +++ b/Charts/Core/Testing/Cxx/TestChartUnicode.cxx @@ -32,10 +32,10 @@ int TestChartUnicode(int argc, char *argv[]) { if (argc < 2) - { + { cout << "Missing font filename." << endl; return EXIT_FAILURE; - } + } std::string fontFile(argv[1]); @@ -72,10 +72,10 @@ int TestChartUnicode(int argc, char *argv[]) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + sin(i * (inc - 3.14))); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestChartXYInvertedAxis.cxx b/Charts/Core/Testing/Cxx/TestChartXYInvertedAxis.cxx index d5a02407a32..c98577a518e 100644 --- a/Charts/Core/Testing/Cxx/TestChartXYInvertedAxis.cxx +++ b/Charts/Core/Testing/Cxx/TestChartXYInvertedAxis.cxx @@ -1532,13 +1532,13 @@ int TestChartXYInvertedAxis( int argc, char * argv[] ) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); table->SetValue(i, 4, 1.0); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestChartXYZ.cxx b/Charts/Core/Testing/Cxx/TestChartXYZ.cxx index 20dc029fb72..e6c520403c1 100644 --- a/Charts/Core/Testing/Cxx/TestChartXYZ.cxx +++ b/Charts/Core/Testing/Cxx/TestChartXYZ.cxx @@ -42,10 +42,10 @@ void ProcessEvents(vtkObject *caller, unsigned long, chart->SetAngle(angle); interactor->Render(); if (angle >= 90) - { + { int timerId = *reinterpret_cast(callerData); interactor->DestroyTimer(timerId); - } + } } } // End of anonymous namespace. @@ -84,11 +84,11 @@ int TestChartXYZ(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); - } + } //chart->SetAroundX(true); // Add the three dimensions we are interested in visualizing. diff --git a/Charts/Core/Testing/Cxx/TestChartsOn3D.cxx b/Charts/Core/Testing/Cxx/TestChartsOn3D.cxx index 406d9a92f9b..d97a094671a 100644 --- a/Charts/Core/Testing/Cxx/TestChartsOn3D.cxx +++ b/Charts/Core/Testing/Cxx/TestChartsOn3D.cxx @@ -94,12 +94,12 @@ int TestChartsOn3D(int , char * []) table->SetNumberOfRows(numPoints); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, tan(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *points = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestColorTransferFunction.cxx b/Charts/Core/Testing/Cxx/TestColorTransferFunction.cxx index 054e18ad2b5..f856880aa1a 100644 --- a/Charts/Core/Testing/Cxx/TestColorTransferFunction.cxx +++ b/Charts/Core/Testing/Cxx/TestColorTransferFunction.cxx @@ -60,14 +60,14 @@ int TestColorTransferFunction(int , char * []) // Finally render the scene and compare the image to a reference image view->GetRenderWindow()->SetMultiSamples(1); if (view->GetContext()->GetDevice()->IsA("vtkOpenGLContextDevice2D")) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } else - { + { cout << "GL version 2 or higher is required." << endl; - } + } return EXIT_SUCCESS; } diff --git a/Charts/Core/Testing/Cxx/TestContext.cxx b/Charts/Core/Testing/Cxx/TestContext.cxx index 63f00a07b38..008436306c1 100644 --- a/Charts/Core/Testing/Cxx/TestContext.cxx +++ b/Charts/Core/Testing/Cxx/TestContext.cxx @@ -79,23 +79,23 @@ bool ContextTest::Paint(vtkContext2D *painter) // Draw some individual lines of different thicknesses. for (int i = 0; i < 10; ++i) - { + { painter->GetPen()->SetColor(255, static_cast(float(i)*25.0), 0); painter->GetPen()->SetWidth(1.0 + float(i)); painter->DrawLine(10, 50 + float(i)*10, 60, 50 + float(i)*10); - } + } // Use the draw lines function now to draw a shape. vtkSmartPointer points = vtkSmartPointer::New(); points->SetNumberOfPoints(30); for (int i = 0; i < 30; ++i) - { + { double point[2] = { float(i) * 25.0 + 10.0, sin(float(i) / 5.0) * 100.0 + 200.0 }; points->SetPoint(i, point); - } + } painter->GetPen()->SetColor(0, 255, 0); painter->GetPen()->SetWidth(5.0); painter->DrawPoly(points); @@ -112,7 +112,7 @@ bool ContextTest::Paint(vtkContext2D *painter) float markerPoints[10*2]; unsigned char markerColors[10*4]; for (int i = 0; i < 10; ++i) - { + { markerPoints[2 * i] = 500.0 + i * 30.0; markerPoints[2 * i + 1] = 20 * sin(markerPoints[2 * i]) + 375.0; @@ -122,32 +122,32 @@ bool ContextTest::Paint(vtkContext2D *painter) markerColors[4 * i + 2] = static_cast(255 * (0.3)); markerColors[4 * i + 3] = static_cast(255 * (1.0 - ((i / 10.0) * 0.25))); - } + } for (int style = VTK_MARKER_NONE + 1; style < VTK_MARKER_UNKNOWN; ++style) - { + { // Increment the y values: for (int i = 1; i < 20; i += 2) - { + { markerPoints[i] += 35.0; - } + } painter->GetPen()->SetWidth(style * 5 + 5); // Not highlighted: painter->DrawMarkers(style, false, markerPoints, 10, markerColors, 4); // Highlight the middle 4 points painter->GetPen()->SetColorF(0.9, 0.8, 0.1, 0.5); painter->DrawMarkers(style, true, markerPoints + 3*2, 4); - } + } // Draw some individual lines of different thicknesses. for (int i = 0; i < 10; ++i) - { + { painter->GetPen()->SetColor(0, static_cast(float(i)*25.0), 255, 255); painter->GetPen()->SetWidth(1.0 + float(i)); painter->DrawPoint(75, 50 + float(i)*10); - } + } painter->GetPen()->SetColor(0, 0, 255); painter->GetPen()->SetWidth(3.0); diff --git a/Charts/Core/Testing/Cxx/TestContextArea.cxx b/Charts/Core/Testing/Cxx/TestContextArea.cxx index 6d43b5b8c5b..ac101e0a81c 100644 --- a/Charts/Core/Testing/Cxx/TestContextArea.cxx +++ b/Charts/Core/Testing/Cxx/TestContextArea.cxx @@ -125,13 +125,13 @@ int TestContextArea(int argc, char *argv[]) area->GetAxis(vtkAxis::RIGHT)->SetTitle("Right Axis"); for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = area->GetAxis(static_cast(i)); axis->GetLabelProperties()->SetColor(.6, .6, .9); axis->GetTitleProperties()->SetColor(.6, .6, .9); axis->GetPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 255); axis->GetGridPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 128); - } + } area->GetDrawAreaItem()->AddItem(imageItem.GetPointer()); area->GetDrawAreaItem()->AddItem(contourItem.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestContextAreaFixedAspect.cxx b/Charts/Core/Testing/Cxx/TestContextAreaFixedAspect.cxx index 66356f2b70b..2bf5189926d 100644 --- a/Charts/Core/Testing/Cxx/TestContextAreaFixedAspect.cxx +++ b/Charts/Core/Testing/Cxx/TestContextAreaFixedAspect.cxx @@ -126,13 +126,13 @@ int TestContextAreaFixedAspect(int argc, char *argv[]) area->GetAxis(vtkAxis::RIGHT)->SetTitle("Right Axis"); for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = area->GetAxis(static_cast(i)); axis->GetLabelProperties()->SetColor(.6, .6, .9); axis->GetTitleProperties()->SetColor(.6, .6, .9); axis->GetPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 255); axis->GetGridPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 128); - } + } area->GetDrawAreaItem()->AddItem(imageItem.GetPointer()); area->GetDrawAreaItem()->AddItem(contourItem.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestContextAreaFixedMargins.cxx b/Charts/Core/Testing/Cxx/TestContextAreaFixedMargins.cxx index 5a52a66c7d0..20c6ea86e96 100644 --- a/Charts/Core/Testing/Cxx/TestContextAreaFixedMargins.cxx +++ b/Charts/Core/Testing/Cxx/TestContextAreaFixedMargins.cxx @@ -126,13 +126,13 @@ int TestContextAreaFixedMargins(int argc, char *argv[]) area->GetAxis(vtkAxis::RIGHT)->SetTitle("Right Axis"); for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = area->GetAxis(static_cast(i)); axis->GetLabelProperties()->SetColor(.6, .6, .9); axis->GetTitleProperties()->SetColor(.6, .6, .9); axis->GetPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 255); axis->GetGridPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 128); - } + } area->GetDrawAreaItem()->AddItem(imageItem.GetPointer()); area->GetDrawAreaItem()->AddItem(contourItem.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestContextAreaFixedRect.cxx b/Charts/Core/Testing/Cxx/TestContextAreaFixedRect.cxx index b9d465cb8c9..8d018d027b1 100644 --- a/Charts/Core/Testing/Cxx/TestContextAreaFixedRect.cxx +++ b/Charts/Core/Testing/Cxx/TestContextAreaFixedRect.cxx @@ -126,13 +126,13 @@ int TestContextAreaFixedRect(int argc, char *argv[]) area->GetAxis(vtkAxis::RIGHT)->SetTitle("Right Axis"); for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = area->GetAxis(static_cast(i)); axis->GetLabelProperties()->SetColor(.6, .6, .9); axis->GetTitleProperties()->SetColor(.6, .6, .9); axis->GetPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 255); axis->GetGridPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 128); - } + } area->GetDrawAreaItem()->AddItem(imageItem.GetPointer()); area->GetDrawAreaItem()->AddItem(contourItem.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestContextScene.cxx b/Charts/Core/Testing/Cxx/TestContextScene.cxx index 0173c7a3d38..8f0e4062405 100644 --- a/Charts/Core/Testing/Cxx/TestContextScene.cxx +++ b/Charts/Core/Testing/Cxx/TestContextScene.cxx @@ -71,10 +71,10 @@ int TestContextScene( int argc, char * argv [] ) int retVal = vtkRegressionTestImage(view->GetRenderWindow()); if(retVal == vtkRegressionTester::DO_INTERACTOR) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } return 0; //return !retVal; } diff --git a/Charts/Core/Testing/Cxx/TestContextUnicode.cxx b/Charts/Core/Testing/Cxx/TestContextUnicode.cxx index 6ef621cfc85..dd509b37ce7 100644 --- a/Charts/Core/Testing/Cxx/TestContextUnicode.cxx +++ b/Charts/Core/Testing/Cxx/TestContextUnicode.cxx @@ -47,10 +47,10 @@ class ContextUnicode : public vtkContextItem int TestContextUnicode(int argc, char * argv []) { if (argc < 2) - { + { cout << "Missing font filename." << endl; return EXIT_FAILURE; - } + } std::string fontFile(argv[1]); @@ -66,10 +66,10 @@ int TestContextUnicode(int argc, char * argv []) int retVal = vtkRegressionTestImage(view->GetRenderWindow()); if(retVal == vtkRegressionTester::DO_INTERACTOR) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } return !retVal; } diff --git a/Charts/Core/Testing/Cxx/TestControlPointsHandleItem.cxx b/Charts/Core/Testing/Cxx/TestControlPointsHandleItem.cxx index dd14ca88bdd..f12471cf05e 100644 --- a/Charts/Core/Testing/Cxx/TestControlPointsHandleItem.cxx +++ b/Charts/Core/Testing/Cxx/TestControlPointsHandleItem.cxx @@ -687,14 +687,14 @@ int TestControlPointsHandleItem(int, char * []) // chart->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::MIDDLE_BUTTON); // chart->SetActionToButton(vtkChart::SELECT, vtkContextMouseEvent::RIGHT_BUTTON); for (int i = 0; i < 4; ++i) - { + { chart->GetAxis(i)->SetVisible(true); chart->GetAxis(i)->SetNumberOfTicks(0); chart->GetAxis(i)->SetBehavior(2); chart->GetAxis(i)->SetLabelsVisible(false); chart->GetAxis(i)->SetMargins(1,1); chart->GetAxis(i)->SetTitle(""); - } + } view->GetScene()->AddItem(chart.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestControlPointsItem.cxx b/Charts/Core/Testing/Cxx/TestControlPointsItem.cxx index 5999fba6211..fa7b37b6b85 100644 --- a/Charts/Core/Testing/Cxx/TestControlPointsItem.cxx +++ b/Charts/Core/Testing/Cxx/TestControlPointsItem.cxx @@ -39,59 +39,59 @@ int TestControlPointsItem(int, char*[]) controlPoints->SetColorTransferFunction(transferFunction.GetPointer()); if (controlPoints->GetColorTransferFunction() != transferFunction.GetPointer()) - { + { std::cerr << "vtkColorTransferControlPointsItem::GetColorTransferFunction " << "failed, bad pointer: " << controlPoints->GetColorTransferFunction() << std::endl; return EXIT_FAILURE; - } + } if (controlPoints->GetNumberOfPoints() != 4 || controlPoints->GetNumberOfSelectedPoints() != 0) - { + { std::cerr << "vtkColorTransferControlPointsItem::SetColorTransferFunction " << "failed, wrong number of points: " << controlPoints->GetNumberOfPoints() << ", " << controlPoints->GetNumberOfSelectedPoints() << std::endl; return EXIT_FAILURE; - } + } vtkNew ids; controlPoints->GetControlPointsIds(ids.GetPointer(), true); if (ids->GetSize() != controlPoints->GetNumberOfPoints() - 2 || ids->GetValue(0) != 1 || ids->GetValue(1) != 2) - { + { std::cerr << "vtkControlPointsItem::GetControlPointsIds" << "failed, bad array: " << ids->GetSize() << ", " << ids->GetValue(0) << ", " << ids->GetValue(1) << std::endl; return EXIT_FAILURE; - } + } controlPoints->GetControlPointsIds(ids.GetPointer()); if (ids->GetSize() != controlPoints->GetNumberOfPoints() || ids->GetValue(0) != 0 || ids->GetValue(1) != 1 || ids->GetValue(2) != 2 || ids->GetValue(3) != 3) - { + { std::cerr << "vtkControlPointsItem::GetControlPointsIds" << "failed, bad array: " << ids->GetSize() << ", " << ids->GetValue(0) << ", " << ids->GetValue(1) << ", " << ids->GetValue(2) << ", " << ids->GetValue(3) << std::endl; return EXIT_FAILURE; - } + } double bounds[4]; controlPoints->GetBounds(bounds); if (bounds[0] != 50. || bounds[1] != 200. || bounds[2] != 0.5 || bounds[3] != 0.5) - { + { std::cerr << "vtkColorTransferControlPointsItem::GetBounds" << "failed, wrong bounds: " << bounds[0] << ", " << bounds[1] << ", " << bounds[2] << ", " << bounds[3] << std::endl; return EXIT_FAILURE; - } + } // MovePoints controlPoints->MovePoints(vtkVector2f(1.,0.), ids.GetPointer()); @@ -103,13 +103,13 @@ int TestControlPointsItem(int, char*[]) controlPoints->GetControlPoint(3, point3); if (point0[0] != 51. || point1[0] != 86. || point2[0] != 171. || point3[0] != 200.) - { + { std::cerr << "vtkColorTransferControlPointsItem::MovePoints" << "failed, wrong pos: " << point0[0] << ", " << point1[0] << ", " << point2[0] << ", " << point3[0] << std::endl; return EXIT_FAILURE; - } + } // SpreadPoints controlPoints->SpreadPoints(1., ids.GetPointer()); @@ -120,13 +120,13 @@ int TestControlPointsItem(int, char*[]) controlPoints->GetControlPoint(3, point3); if (point0[0] != 51. || point1[0] >= 86. || point2[0] <= 171. || point3[0] != 200.) - { + { std::cerr << "vtkColorTransferControlPointsItem::SpreadPoints(1)" << "failed, wrong pos: " << point0[0] << ", " << point1[0] << ", " << point2[0] << ", " << point3[0] << std::endl; return EXIT_FAILURE; - } + } controlPoints->SpreadPoints(-1., ids.GetPointer()); @@ -138,13 +138,13 @@ int TestControlPointsItem(int, char*[]) point1[0] <= 86. || point1[0] >= 87. || point2[0] <= 170. || point2[0] >= 171.|| point3[0] != 199.) - { + { std::cerr << "vtkColorTransferControlPointsItem::SpreadPoints(-1)" << "failed, wrong pos: " << point0[0] << ", " << point1[0] << ", " << point2[0] << ", " << point3[0] << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Charts/Core/Testing/Cxx/TestControlPointsItemEvents.cxx b/Charts/Core/Testing/Cxx/TestControlPointsItemEvents.cxx index df892e3a774..fd3a6b0bf79 100644 --- a/Charts/Core/Testing/Cxx/TestControlPointsItemEvents.cxx +++ b/Charts/Core/Testing/Cxx/TestControlPointsItemEvents.cxx @@ -50,13 +50,13 @@ class vtkTFCallback : public vtkCommand vtkColorTransferFunction* self = reinterpret_cast< vtkColorTransferFunction* >( caller ); if (!self) - { + { return; - } + } if (this->EventSpy.count(event) == 0) - { + { this->EventSpy[event] = 0; - } + } ++this->EventSpy[event]; std::cout << "InvokedEvent: " << event << this->EventSpy[event] << std::endl; } @@ -116,7 +116,7 @@ int TestControlPointsItemEvents(int, char*[]) cbk->EventSpy[vtkCommand::EndInteractionEvent] != 1 || cbk->EventSpy[vtkCommand::StartEvent] != 2 || cbk->EventSpy[vtkCommand::EndEvent] != 2) - { + { std::cerr << "Wrong number of fired events : " << cbk->EventSpy[vtkCommand::ModifiedEvent] << " " << cbk->EventSpy[vtkCommand::StartInteractionEvent] << " " @@ -125,7 +125,7 @@ int TestControlPointsItemEvents(int, char*[]) << cbk->EventSpy[vtkCommand::StartEvent] << " " << cbk->EventSpy[vtkCommand::EndEvent] << std::endl; return EXIT_FAILURE; - } + } cbk->EventSpy.clear(); // Move all the points to the right. controlPoints->MovePoints(vtkVector2f(5, 0.)); @@ -137,7 +137,7 @@ int TestControlPointsItemEvents(int, char*[]) cbk->EventSpy[vtkCommand::EndInteractionEvent] != 0 || cbk->EventSpy[vtkCommand::StartEvent] != 1 || cbk->EventSpy[vtkCommand::EndEvent] != 1) - { + { std::cerr << "Wrong number of fired events : " << cbk->EventSpy[vtkCommand::ModifiedEvent] << " " << cbk->EventSpy[vtkCommand::StartInteractionEvent] << " " @@ -146,7 +146,7 @@ int TestControlPointsItemEvents(int, char*[]) << cbk->EventSpy[vtkCommand::StartEvent] << " " << cbk->EventSpy[vtkCommand::EndEvent] << std::endl; return EXIT_FAILURE; - } + } cbk->EventSpy.clear(); @@ -168,7 +168,7 @@ int TestControlPointsItemEvents(int, char*[]) cbk->EventSpy[vtkCommand::EndInteractionEvent] != 0 || cbk->EventSpy[vtkCommand::StartEvent] != 0 || cbk->EventSpy[vtkCommand::EndEvent] != 0) - { + { std::cerr << "Wrong number of fired events : " << cbk->EventSpy[vtkCommand::ModifiedEvent] << " " << cbk->EventSpy[vtkCommand::StartInteractionEvent] << " " @@ -177,7 +177,7 @@ int TestControlPointsItemEvents(int, char*[]) << cbk->EventSpy[vtkCommand::StartEvent] << " " << cbk->EventSpy[vtkCommand::EndEvent] << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Charts/Core/Testing/Cxx/TestFreeTypeRender.cxx b/Charts/Core/Testing/Cxx/TestFreeTypeRender.cxx index 2b0d3e26820..fd86e2ff080 100644 --- a/Charts/Core/Testing/Cxx/TestFreeTypeRender.cxx +++ b/Charts/Core/Testing/Cxx/TestFreeTypeRender.cxx @@ -77,9 +77,9 @@ int TestFreeTypeRender(int argc, char * argv []) int retVal = vtkRegressionTestImage(view->GetRenderWindow()); if(retVal == vtkRegressionTester::DO_INTERACTOR) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } return !retVal; } diff --git a/Charts/Core/Testing/Cxx/TestFunctionalBagPlot.cxx b/Charts/Core/Testing/Cxx/TestFunctionalBagPlot.cxx index e03c59b0373..9615917d201 100644 --- a/Charts/Core/Testing/Cxx/TestFunctionalBagPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestFunctionalBagPlot.cxx @@ -39,28 +39,28 @@ int TestFunctionalBagPlot(int, char * []) vtkNew inputTable; vtkNew arr[numCols]; for (int i = 0; i < numCols; i++) - { + { std::stringstream ss; ss << "Y" << i; arr[i]->SetName(ss.str().c_str()); arr[i]->SetNumberOfValues(numVals); for (int j = 0; j < numVals; j++) - { + { arr[i]->SetValue(j, (i+1) * fabs(sin((j * 2.f *vtkMath::Pi()) / static_cast(numVals))) * j + i * 20); - } - inputTable->AddColumn(arr[i].GetPointer()); } + inputTable->AddColumn(arr[i].GetPointer()); + } // Create a X-axis column vtkNew xArr; xArr->SetName("X"); xArr->SetNumberOfValues(numVals); for (int j = 0; j < numVals; j++) - { + { xArr->SetValue(j, j * 2.0); - } + } inputTable->AddColumn(xArr.GetPointer()); // Create the bag columns @@ -74,7 +74,7 @@ int TestFunctionalBagPlot(int, char * []) q2Arr->SetNumberOfTuples(numVals); for (int i = 0; i < numVals; i++) - { + { double v0, v1; v0 = arr[1]->GetVariantValue(i).ToFloat(); v1 = arr[5]->GetVariantValue(i).ToFloat(); @@ -83,7 +83,7 @@ int TestFunctionalBagPlot(int, char * []) v0 = arr[2]->GetVariantValue(i).ToFloat(); v1 = arr[4]->GetVariantValue(i).ToFloat(); q2Arr->SetTuple2(i, v0, v1); - } + } inputTable->AddColumn(q3Arr.GetPointer()); inputTable->AddColumn(q2Arr.GetPointer()); @@ -114,7 +114,7 @@ int TestFunctionalBagPlot(int, char * []) lookup->SetRange(0, numCols-1); lookup->Build(); for (int j = 0; j < numCols; j++) - { + { vtkNew plot; double rgb[3]; lookup->GetColor(j, rgb); @@ -122,7 +122,7 @@ int TestFunctionalBagPlot(int, char * []) plot->SetInputData(inputTable.GetPointer(), "X", inputTable->GetColumn(j)->GetName()); chart->AddPlot(plot.GetPointer()); - } + } // Render the scene view->GetInteractor()->Initialize(); diff --git a/Charts/Core/Testing/Cxx/TestGLSL.cxx b/Charts/Core/Testing/Cxx/TestGLSL.cxx index 22333ce71cd..b810759a554 100644 --- a/Charts/Core/Testing/Cxx/TestGLSL.cxx +++ b/Charts/Core/Testing/Cxx/TestGLSL.cxx @@ -103,14 +103,14 @@ int TestGLSL( int, char * [] ) view->Render(); if (test->IsCompiled) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } else - { + { cout << "GLSL 1.20 required, shader failed to compile." << endl; - } + } return EXIT_SUCCESS; } @@ -123,55 +123,55 @@ bool GLSLTestItem::Paint(vtkContext2D *painter) vtkOpenGL2ContextDevice2D *device = vtkOpenGL2ContextDevice2D::SafeDownCast(painter->GetDevice()); if (device) - { + { this->BuildShader(device->GetRenderWindow()); if (!this->IsCompiled) - { + { return false; - } } + } else - { + { this->IsCompiled = false; return false; - } + } // Draw points without our shader code for (int i = 0; i < 8; ++i) - { + { float pos[] = { 50.0f, static_cast(i)*25.0f+5.0f }; painter->GetPen()->SetColor(255, static_cast(float(i)*35.0), 0); painter->GetPen()->SetWidth(static_cast(i)*5.0f+1.0f); painter->DrawPointSprites(0, pos, 1); - } + } // Draw the points using the first shader program this->program->Use(); for (int i = 0; i < 8; ++i) - { + { float pos[] = { 100.0f, static_cast(i)*25.0f+5.0f }; painter->GetPen()->SetColor(255, 0, static_cast(float(i)*35.0)); painter->GetPen()->SetWidth(static_cast(i)*5.0f+1.0f); painter->DrawPointSprites(0, pos, 1); - } + } this->program->Restore(); // Draw the points using the second shader program this->program2->Use(); for (int i = 0; i < 8; ++i) - { + { float pos[] = { 150.0f, static_cast(i)*25.0f+5.0f }; painter->GetPen()->SetColor(static_cast(float(i)*35.0), 255, 0); painter->GetPen()->SetWidth(static_cast(i)*5.0f+1.0f); painter->DrawPointSprites(0, pos, 1); - } + } this->program2->Restore(); return true; @@ -180,29 +180,29 @@ bool GLSLTestItem::Paint(vtkContext2D *painter) void GLSLTestItem::ReleaseGraphicsResources() { if (this->program) - { + { this->program->ReleaseGraphicsResources(); - } + } if (this->program2) - { + { this->program2->ReleaseGraphicsResources(); - } + } } void GLSLTestItem::BuildShader(vtkOpenGLRenderWindow* glContext) { if (this->program) - { + { return; - } + } // Check if GLSL is supported if (!vtkShaderProgram2::IsSupported(glContext)) - { + { vtkErrorMacro("GLSL is not supported on this system."); this->IsCompiled = false; return; - } + } this->program = vtkSmartPointer::New(); this->program->SetContext(glContext); @@ -237,18 +237,18 @@ void GLSLTestItem::BuildShader(vtkOpenGLRenderWindow* glContext) // Build the shader programs this->program->Build(); if(this->program->GetLastBuildStatus() != VTK_SHADER_PROGRAM2_LINK_SUCCEEDED) - { + { vtkErrorMacro("Couldn't build the shader program. It could be an error in a shader, or a driver bug."); this->IsCompiled = false; return; - } + } this->program2->Build(); if(this->program2->GetLastBuildStatus() != VTK_SHADER_PROGRAM2_LINK_SUCCEEDED) - { + { vtkErrorMacro("Couldn't build the shader program. It could be an error in a shader, or a driver bug."); this->IsCompiled = false; return; - } + } this->IsCompiled = true; } diff --git a/Charts/Core/Testing/Cxx/TestHistogram2D.cxx b/Charts/Core/Testing/Cxx/TestHistogram2D.cxx index 800273e65f7..e8c0936773e 100644 --- a/Charts/Core/Testing/Cxx/TestHistogram2D.cxx +++ b/Charts/Core/Testing/Cxx/TestHistogram2D.cxx @@ -45,13 +45,13 @@ int TestHistogram2D(int, char * []) double *dPtr = static_cast(data->GetScalarPointer(0, 0, 0)); for (int i = 0; i < size; ++i) - { + { for (int j = 0; j < size; ++j) - { + { dPtr[i * size + j] = sin(vtkMath::RadiansFromDegrees(double(2*i))) * cos(vtkMath::RadiansFromDegrees(double(j))); - } } + } chart->SetInputData(data.GetPointer()); vtkNew transferFunction; diff --git a/Charts/Core/Testing/Cxx/TestInteractiveChartXYZ.cxx b/Charts/Core/Testing/Cxx/TestInteractiveChartXYZ.cxx index 070f51c09b8..78071389b47 100644 --- a/Charts/Core/Testing/Cxx/TestInteractiveChartXYZ.cxx +++ b/Charts/Core/Testing/Cxx/TestInteractiveChartXYZ.cxx @@ -57,12 +57,12 @@ int TestInteractiveChartXYZ(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, i); - } + } // Add the dimensions we are interested in visualizing. vtkNew plot; diff --git a/Charts/Core/Testing/Cxx/TestLegendHiddenPlots.cxx b/Charts/Core/Testing/Cxx/TestLegendHiddenPlots.cxx index cbc77466a5f..51b9c366297 100644 --- a/Charts/Core/Testing/Cxx/TestLegendHiddenPlots.cxx +++ b/Charts/Core/Testing/Cxx/TestLegendHiddenPlots.cxx @@ -60,12 +60,12 @@ int TestLegendHiddenPlots(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, tan(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *points = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestLinePlot.cxx b/Charts/Core/Testing/Cxx/TestLinePlot.cxx index 6a81b30eb25..f8a5f57dcab 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlot.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlot.cxx @@ -56,13 +56,13 @@ int TestLinePlot( int, char * [] ) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); table->SetValue(i, 4, 1.0); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); @@ -87,11 +87,11 @@ int TestLinePlot( int, char * [] ) double bds[4]; line->GetUnscaledInputBounds(bds); if (bds[0] * bds[1] > 0. || bds[2] * bds[3] > 0.) - { + { cerr << "ERROR: Data on both X and Y axes expected to cross origin.\n"; status = EXIT_FAILURE; - } + } // Verify that log-scaling is proper for arr1 y axis (which // is not plotted so as to avoid changing baseline images). @@ -100,11 +100,11 @@ int TestLinePlot( int, char * [] ) line->Update(); line->GetUnscaledInputBounds(bds); if (bds[0] * bds[1] > 0. || bds[2] * bds[3] <= 0.) - { + { cerr << "ERROR: Data on X axis expected to cross origin.\n"; status = EXIT_FAILURE; - } + } return status; } diff --git a/Charts/Core/Testing/Cxx/TestLinePlot2.cxx b/Charts/Core/Testing/Cxx/TestLinePlot2.cxx index 21d25ce0f29..cd52368144f 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlot2.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlot2.cxx @@ -54,10 +54,10 @@ int TestLinePlot2(int, char * []) int numPoints = 31; table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, data_x[i] ); table->SetValue(i, 1, data_y[i]); - } + } // Add a plot of points, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestLinePlot3D.cxx b/Charts/Core/Testing/Cxx/TestLinePlot3D.cxx index 599dbee72fa..1d902a6e955 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlot3D.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlot3D.cxx @@ -64,7 +64,7 @@ int TestLinePlot3D(int, char * []) float varXDerivative[3]; const float deltaT = 0.01f; for (unsigned int ii = 0; ii < numberOfTimePoints; ++ii) - { + { varXSolution->SetValue(ii, 0, varX[0]); varXSolution->SetValue(ii, 1, varX[1]); varXSolution->SetValue(ii, 2, varX[2]); @@ -72,7 +72,7 @@ int TestLinePlot3D(int, char * []) varX[0] += varXDerivative[0] * deltaT; varX[1] += varXDerivative[1] * deltaT; varX[2] += varXDerivative[2] * deltaT; - } + } // Set up a 3D scene and add an XYZ chart to it. vtkNew view; diff --git a/Charts/Core/Testing/Cxx/TestLinePlotAxisFonts.cxx b/Charts/Core/Testing/Cxx/TestLinePlotAxisFonts.cxx index 3e1b517147b..e3e6080b450 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotAxisFonts.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotAxisFonts.cxx @@ -56,10 +56,10 @@ int TestLinePlotAxisFonts(int, char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc)); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestLinePlotDouble.cxx b/Charts/Core/Testing/Cxx/TestLinePlotDouble.cxx index e397a47961d..05b428e660a 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotDouble.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotDouble.cxx @@ -52,12 +52,12 @@ int TestLinePlotDouble(int, char *[]) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, 1.0e-80 * cos(i * inc - 1.0) * 1.0e-8); table->SetValue(i, 2, 1.0e-80 * sin(i * inc) * 1.0e-8); table->SetValue(i, 3, 1.0e80 * sin(i * inc - 1.0)); - } + } table->SetValue(66, 2, vtkMath::Nan()); table->SetValue(4, 3, vtkMath::Inf()); diff --git a/Charts/Core/Testing/Cxx/TestLinePlotDouble2.cxx b/Charts/Core/Testing/Cxx/TestLinePlotDouble2.cxx index 99ae71040cf..701f2298628 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotDouble2.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotDouble2.cxx @@ -45,11 +45,11 @@ int TestLinePlotDouble2(int, char *[]) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { double x(1 + 1e-11 * inc * i); table->SetValue(i, 0, x); table->SetValue(i, 1, cos((x - 1.0) * 1.0e11)); - } + } vtkPlot *line = chart->AddPlot(vtkChart::LINE); line->SetInputData(table.GetPointer(), 0, 1); diff --git a/Charts/Core/Testing/Cxx/TestLinePlotInteraction.cxx b/Charts/Core/Testing/Cxx/TestLinePlotInteraction.cxx index 361ba857596..0d88940d7d2 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotInteraction.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotInteraction.cxx @@ -156,12 +156,12 @@ int TestLinePlotInteraction(int, char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestLinePlotSelection.cxx b/Charts/Core/Testing/Cxx/TestLinePlotSelection.cxx index 0a1ca59b480..7a35e3578ff 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotSelection.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotSelection.cxx @@ -59,12 +59,12 @@ int TestLinePlotSelection(int, char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestLinePlotSelection2.cxx b/Charts/Core/Testing/Cxx/TestLinePlotSelection2.cxx index 701bc8693e0..86587655008 100644 --- a/Charts/Core/Testing/Cxx/TestLinePlotSelection2.cxx +++ b/Charts/Core/Testing/Cxx/TestLinePlotSelection2.cxx @@ -59,12 +59,12 @@ int TestLinePlotSelection2(int, char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestMultipleChartRenderers.cxx b/Charts/Core/Testing/Cxx/TestMultipleChartRenderers.cxx index cbaeb53733f..7ac1830d4c2 100644 --- a/Charts/Core/Testing/Cxx/TestMultipleChartRenderers.cxx +++ b/Charts/Core/Testing/Cxx/TestMultipleChartRenderers.cxx @@ -48,7 +48,7 @@ int TestMultipleChartRenderers(int , char * []) 0.5,0.5,1.0,1.0}; for ( int i=0; i < 4; ++i) - { + { VTK_CREATE(vtkRenderer, ren); ren->SetBackground(1.0,1.0,1.0); ren->SetViewport(&viewports[i*4]); @@ -84,12 +84,12 @@ int TestMultipleChartRenderers(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int j = 0; j < numPoints; ++j) - { + { table->SetValue(j, 0, j * inc); table->SetValue(j, 1, cos(j * inc) + 0.0); table->SetValue(j, 2, sin(j * inc) + 0.0); table->SetValue(j, 3, sin(j * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); @@ -104,7 +104,7 @@ int TestMultipleChartRenderers(int , char * []) line->SetInputData(table, 0, 3); line->SetColor(0, 0, 255, 255); line->SetWidth(4.0); - } + } iren->Initialize(); iren->Start(); diff --git a/Charts/Core/Testing/Cxx/TestMultipleRenderers.cxx b/Charts/Core/Testing/Cxx/TestMultipleRenderers.cxx index d9c47f8ebc8..69a4ffc06d5 100644 --- a/Charts/Core/Testing/Cxx/TestMultipleRenderers.cxx +++ b/Charts/Core/Testing/Cxx/TestMultipleRenderers.cxx @@ -92,12 +92,12 @@ int TestMultipleRenderers(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestMultipleScalarsToColors.cxx b/Charts/Core/Testing/Cxx/TestMultipleScalarsToColors.cxx index 26f0ba0aef6..2fd8439923a 100644 --- a/Charts/Core/Testing/Cxx/TestMultipleScalarsToColors.cxx +++ b/Charts/Core/Testing/Cxx/TestMultipleScalarsToColors.cxx @@ -76,7 +76,7 @@ int TestMultipleScalarsToColors(int , char * []) opacityFunction->AddPoint(0.,0.); opacityFunction->AddPoint(1.,1.); for ( int i=0; i < 4; ++i) - { + { VTK_CREATE(vtkRenderer, ren); ren->SetBackground(1.0,1.0,1.0); ren->SetViewport(&viewports[i*4]); @@ -95,9 +95,9 @@ int TestMultipleScalarsToColors(int , char * []) chartScene->SetRenderer(ren); switch (i) - { + { case 0: - { + { vtkSmartPointer item = vtkSmartPointer::New(); item->SetLookupTable(lookupTable); @@ -107,9 +107,9 @@ int TestMultipleScalarsToColors(int , char * []) chart->GetAxis(1)->SetVisible(false); chart->SetTitle("vtkLookupTable"); break; - } + } case 1: - { + { vtkSmartPointer item = vtkSmartPointer::New(); item->SetColorTransferFunction(colorTransferFunction); @@ -118,9 +118,9 @@ int TestMultipleScalarsToColors(int , char * []) chart->AddPlot(item); chart->SetTitle("vtkColorTransferFunction"); break; - } + } case 2: - { + { vtkSmartPointer item = vtkSmartPointer::New(); item->SetColorTransferFunction(colorTransferFunction); @@ -129,9 +129,9 @@ int TestMultipleScalarsToColors(int , char * []) chart->AddPlot(item); chart->SetTitle("vtkColorTransferFunction + vtkPiecewiseFunction"); break; - } + } case 3: - { + { vtkSmartPointer item = vtkSmartPointer::New(); item->SetPiecewiseFunction(opacityFunction); @@ -143,11 +143,11 @@ int TestMultipleScalarsToColors(int , char * []) chart->AddPlot(controlPointsItem); chart->SetTitle("vtkPiecewiseFunction"); break; - } + } default: break; - } } + } // Needed to ensure there has been a render. This test supports as low as // OpenGL 1.2, but further granularity must be added to the device to detect @@ -161,14 +161,14 @@ int TestMultipleScalarsToColors(int , char * []) #endif if (openGL2Backend || actor->GetContext()->GetDevice()->IsA("vtkOpenGL2ContextDevice2D")) - { + { iren->Initialize(); iren->Start(); - } + } else - { + { cout << "GL version 2 or higher is required." << endl; - } + } return EXIT_SUCCESS; } diff --git a/Charts/Core/Testing/Cxx/TestParallelCoordinates.cxx b/Charts/Core/Testing/Cxx/TestParallelCoordinates.cxx index 01788f62491..93072459d26 100644 --- a/Charts/Core/Testing/Cxx/TestParallelCoordinates.cxx +++ b/Charts/Core/Testing/Cxx/TestParallelCoordinates.cxx @@ -53,12 +53,12 @@ int TestParallelCoordinates(int , char* []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, tan(i * inc) + 0.5); - } + } chart->GetPlot(0)->SetInputData(table.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestParallelCoordinatesDouble.cxx b/Charts/Core/Testing/Cxx/TestParallelCoordinatesDouble.cxx index 82a72619fb2..d1c5f6e8d24 100644 --- a/Charts/Core/Testing/Cxx/TestParallelCoordinatesDouble.cxx +++ b/Charts/Core/Testing/Cxx/TestParallelCoordinatesDouble.cxx @@ -52,12 +52,12 @@ int TestParallelCoordinatesDouble(int , char* []) float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) * 1.0e-82); table->SetValue(i, 2, sin(i * inc) * 1.0e+89); table->SetValue(i, 3, tan(i * inc) + 0.5); - } + } chart->GetPlot(0)->SetInputData(table.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestPieChart.cxx b/Charts/Core/Testing/Cxx/TestPieChart.cxx index 5af78b56482..fe379ebc31c 100644 --- a/Charts/Core/Testing/Cxx/TestPieChart.cxx +++ b/Charts/Core/Testing/Cxx/TestPieChart.cxx @@ -51,10 +51,10 @@ int TestPieChart(int , char * []) arrData->SetName("2008 Circulation"); for (int i = 0; i < NUM_ITEMS; i++) - { + { arrData->InsertNextValue(data[i]); labelArray->InsertNextValue(labels[i]); - } + } table->AddColumn(arrData.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestPlotMatrix.cxx b/Charts/Core/Testing/Cxx/TestPlotMatrix.cxx index ca4b1c3e11f..27a4e955dd1 100644 --- a/Charts/Core/Testing/Cxx/TestPlotMatrix.cxx +++ b/Charts/Core/Testing/Cxx/TestPlotMatrix.cxx @@ -53,12 +53,12 @@ int TestPlotMatrix( int, char * [] ) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, sin(i * inc) + 0.5); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestPropItem.cxx b/Charts/Core/Testing/Cxx/TestPropItem.cxx index 8f3f94b5f5b..77b913c35f2 100644 --- a/Charts/Core/Testing/Cxx/TestPropItem.cxx +++ b/Charts/Core/Testing/Cxx/TestPropItem.cxx @@ -135,13 +135,13 @@ int TestPropItem(int argc, char *argv[]) area->GetAxis(vtkAxis::RIGHT)->SetTitle("Right Axis"); for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = area->GetAxis(static_cast(i)); axis->GetLabelProperties()->SetColor(.6, .6, .9); axis->GetTitleProperties()->SetColor(.6, .6, .9); axis->GetPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 255); axis->GetGridPen()->SetColor(.6 * 255, .6 * 255, .9 * 255, 128); - } + } area->GetDrawAreaItem()->AddItem(imageItem.GetPointer()); area->GetDrawAreaItem()->AddItem(contourItem.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestQtDiagram.cxx b/Charts/Core/Testing/Cxx/TestQtDiagram.cxx index 5bf227b621e..66b43c110cc 100644 --- a/Charts/Core/Testing/Cxx/TestQtDiagram.cxx +++ b/Charts/Core/Testing/Cxx/TestQtDiagram.cxx @@ -64,12 +64,12 @@ int TestQtDiagram( int argc, char * argv [] ) // Force the use of the Qt based rendering strategy - fail if not available if(!vtkOpenGLContextDevice2D::SafeDownCast(actor->GetContext()->GetDevice()) ->SetStringRendererToQt()) - { + { // This should never happen as this test is only compiled when VTK_USE_QT // is defined. cerr << "Qt label rendering not available." << endl; return 1; - } + } // Set up the interactor, turn off antialiasing for the tests. VTK_CREATE(vtkRenderWindowInteractor, interactor); diff --git a/Charts/Core/Testing/Cxx/TestScalarsToColors.cxx b/Charts/Core/Testing/Cxx/TestScalarsToColors.cxx index fc31a5977aa..918d59e8c53 100644 --- a/Charts/Core/Testing/Cxx/TestScalarsToColors.cxx +++ b/Charts/Core/Testing/Cxx/TestScalarsToColors.cxx @@ -84,14 +84,14 @@ int TestScalarsToColors(int , char * []) #endif if (openGL2Backend || view->GetContext()->GetDevice()->IsA("vtkOpenGL2ContextDevice2D")) - { + { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); - } + } else - { + { cout << "GL version 2 or higher is required." << endl; - } + } return EXIT_SUCCESS; } diff --git a/Charts/Core/Testing/Cxx/TestScatterPlot.cxx b/Charts/Core/Testing/Cxx/TestScatterPlot.cxx index 6732bd9b9aa..740448cbf94 100644 --- a/Charts/Core/Testing/Cxx/TestScatterPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestScatterPlot.cxx @@ -59,20 +59,20 @@ int TestScatterPlot(int , char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc) + 0.0); table->SetValue(i, 2, sin(i * inc) + 0.0); table->SetValue(i, 3, tan(i * inc) + 0.5); if (i % 2) - { + { table->SetValue(i, 4, vtkStdString("Odd")); - } + } else - { + { table->SetValue(i, 4, vtkStdString("Even")); - } } + } // Add multiple line plots, setting the colors etc vtkPlot *points = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/Testing/Cxx/TestScatterPlotMatrix.cxx b/Charts/Core/Testing/Cxx/TestScatterPlotMatrix.cxx index ba98f5c972c..53ee3170163 100644 --- a/Charts/Core/Testing/Cxx/TestScatterPlotMatrix.cxx +++ b/Charts/Core/Testing/Cxx/TestScatterPlotMatrix.cxx @@ -57,13 +57,13 @@ int TestScatterPlotMatrix(int, char * []) float inc = 4.0 * vtkMath::Pi() / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc)); table->SetValue(i, 2, sin(i * inc)); table->SetValue(i, 3, sin(i * inc) + 0.5); table->SetValue(i, 4, tan(i * inc)); - } + } // Set the scatter plot matrix up to analyze all columns in the table. matrix->SetInput(table.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestScatterPlotMatrixVisible.cxx b/Charts/Core/Testing/Cxx/TestScatterPlotMatrixVisible.cxx index d595dd2b535..5fe6d1d6824 100644 --- a/Charts/Core/Testing/Cxx/TestScatterPlotMatrixVisible.cxx +++ b/Charts/Core/Testing/Cxx/TestScatterPlotMatrixVisible.cxx @@ -55,13 +55,13 @@ int TestScatterPlotMatrixVisible(int, char * []) float inc = 7.5 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc)); table->SetValue(i, 2, sin(i * inc)); table->SetValue(i, 3, sin(i * inc) + 0.5); table->SetValue(i, 4, tan(i * inc)); - } + } // Select a few columns in the table to analyze. matrix->SetInput(table.GetPointer()); diff --git a/Charts/Core/Testing/Cxx/TestScientificPlot.cxx b/Charts/Core/Testing/Cxx/TestScientificPlot.cxx index 7ad66bef4d5..9c739bbec10 100644 --- a/Charts/Core/Testing/Cxx/TestScientificPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestScientificPlot.cxx @@ -53,13 +53,13 @@ int TestScientificPlot(int, char * []) float inc = 3.0 / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { double v = -1.0 + i * inc; table->SetValue(i, 0, v); table->SetValue(i, 1, cos(v)); table->SetValue(i, 2, sin(v) + 0.0); table->SetValue(i, 3, v*v*v); - } + } // Add multiple line plots, setting the colors etc vtkPlot *line = chart->AddPlot(vtkChart::LINE); diff --git a/Charts/Core/Testing/Cxx/TestStackedBarGraph.cxx b/Charts/Core/Testing/Cxx/TestStackedBarGraph.cxx index dc22ba7de2a..8c9210dc0a2 100644 --- a/Charts/Core/Testing/Cxx/TestStackedBarGraph.cxx +++ b/Charts/Core/Testing/Cxx/TestStackedBarGraph.cxx @@ -53,9 +53,9 @@ static void build_array(const char *name, vtkIntArray *array, const int c_array[ { array->SetName(name); for (int i = 0; i < num_months; ++i) - { + { array->InsertNextValue(c_array[i]); - } + } } //---------------------------------------------------------------------------- diff --git a/Charts/Core/Testing/Cxx/TestStackedPlot.cxx b/Charts/Core/Testing/Cxx/TestStackedPlot.cxx index f0ad065b730..468d60be3a6 100644 --- a/Charts/Core/Testing/Cxx/TestStackedPlot.cxx +++ b/Charts/Core/Testing/Cxx/TestStackedPlot.cxx @@ -88,7 +88,7 @@ int TestStackedPlot(int , char * []) table->SetNumberOfRows(12); for (int i = 0; i < 12; i++) - { + { arrMonthLabel->SetValue(i,month_labels[i]); arrXTickPositions->SetValue(i,i); @@ -97,7 +97,7 @@ int TestStackedPlot(int , char * []) arrPeriodical->SetValue(i,periodical[i]); arrAudiobook->SetValue(i,audiobook[i]); arrVideo->SetValue(i,video[i]); - } + } // Set the Month Labels chart->GetAxis(1)->SetCustomTickPositions(arrXTickPositions.GetPointer(), diff --git a/Charts/Core/Testing/Cxx/TestSurfacePlot.cxx b/Charts/Core/Testing/Cxx/TestSurfacePlot.cxx index 01c611b3d46..68d1322eef2 100644 --- a/Charts/Core/Testing/Cxx/TestSurfacePlot.cxx +++ b/Charts/Core/Testing/Cxx/TestSurfacePlot.cxx @@ -43,20 +43,20 @@ int TestSurfacePlot(int , char * []) vtkIdType numPoints = 70; float inc = 9.424778 / (numPoints - 1); for (vtkIdType i = 0; i < numPoints; ++i) - { + { vtkNew arr; table->AddColumn(arr.GetPointer()); - } + } table->SetNumberOfRows(static_cast(numPoints)); for (vtkIdType i = 0; i < numPoints; ++i) - { + { float x = i * inc; for (vtkIdType j = 0; j < numPoints; ++j) - { + { float y = j * inc; table->SetValue(i, j, sin(sqrt(x*x + y*y))); - } } + } // Set up the surface plot we wish to visualize and add it to the chart. plot->SetXRange(0, 9.424778); diff --git a/Charts/Core/Testing/Cxx/TestZoomAxis.cxx b/Charts/Core/Testing/Cxx/TestZoomAxis.cxx index e89397ab425..18e18a08974 100644 --- a/Charts/Core/Testing/Cxx/TestZoomAxis.cxx +++ b/Charts/Core/Testing/Cxx/TestZoomAxis.cxx @@ -53,10 +53,10 @@ int TestZoomAxis(int, char * []) float inc = 9.5f / (numPoints-1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) - { + { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, sin(i * inc)); - } + } // Add multiple line plots, setting the colors etc vtkPlot *plot = chart->AddPlot(vtkChart::POINTS); diff --git a/Charts/Core/vtkAxis.cxx b/Charts/Core/vtkAxis.cxx index 59146ef39d2..b8074245ca8 100644 --- a/Charts/Core/vtkAxis.cxx +++ b/Charts/Core/vtkAxis.cxx @@ -122,11 +122,11 @@ vtkAxis::~vtkAxis() void vtkAxis::SetPosition(int position) { if (this->Position != position) - { + { this->Position = position; // Draw the axis label switch (this->Position) - { + { case vtkAxis::LEFT: this->TitleProperties->SetOrientation(90.0); this->TitleProperties->SetVerticalJustificationToBottom(); @@ -157,19 +157,19 @@ void vtkAxis::SetPosition(int position) this->LabelProperties->SetJustificationToRight(); this->LabelProperties->SetVerticalJustificationToCentered(); break; - } } + } } //----------------------------------------------------------------------------- void vtkAxis::SetPoint1(const vtkVector2f &pos) { if (this->Position1 != pos) - { + { this->Position1 = pos; this->Resized = true; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -188,11 +188,11 @@ vtkVector2f vtkAxis::GetPosition1() void vtkAxis::SetPoint2(const vtkVector2f &pos) { if (this->Position2 != pos) - { + { this->Position2 = pos; this->Resized = true; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -211,26 +211,26 @@ vtkVector2f vtkAxis::GetPosition2() void vtkAxis::SetNumberOfTicks(int numberOfTicks) { if (this->NumberOfTicks != numberOfTicks) - { + { this->TickMarksDirty = true; this->Resized = true; this->NumberOfTicks = numberOfTicks; this->Modified(); - } + } } //----------------------------------------------------------------------------- void vtkAxis::Update() { if (!this->Visible || this->BuildTime > this->MTime) - { + { return; - } + } this->UpdateLogScaleActive(false); if ((this->Behavior == vtkAxis::AUTO || this->Behavior == vtkAxis::FIXED) && this->TickMarksDirty) - { + { // Regenerate the tick marks/positions if necessary // Calculate where the first tick mark should be drawn // FIXME: We need a specific resize event, to handle position change @@ -241,61 +241,61 @@ void vtkAxis::Update() double last = first; double interval(this->TickInterval); if (this->Minimum > this->Maximum) - { + { interval *= -1.0; - } + } for (int i = 0; i < 500; ++i) - { + { last += interval; if ((interval > 0.0 && last > this->Maximum) || (interval <= 0.0 && last < this->Maximum)) - { + { this->GenerateTickLabels(first, last - this->TickInterval); break; - } } } + } // Figure out what type of behavior we should follow if (this->Resized && (this->Behavior == vtkAxis::AUTO || this->Behavior == vtkAxis::FIXED)) - { + { this->RecalculateTickSpacing(); this->Resized = false; - } + } // Figure out the scaling and origin for the scene double scaling = 0.0; double origin = 0.0; if (this->Point1[0] == this->Point2[0]) // x1 == x2, therefore vertical - { + { scaling = (this->Point2[1] - this->Point1[1]) / (this->Maximum - this->Minimum); origin = this->Point1[1]; - } + } else - { + { scaling = (this->Point2[0] - this->Point1[0]) / (this->Maximum - this->Minimum); origin = this->Point1[0]; - } + } if (this->TickPositions->GetNumberOfTuples() != this->TickLabels->GetNumberOfTuples()) - { + { // Generate the tick labels based on the tick positions this->GenerateTickLabels(); - } + } vtkIdType n = this->TickPositions->GetNumberOfTuples(); this->TickScenePositions->SetNumberOfTuples(n); for (vtkIdType i = 0; i < n; ++i) - { + { int iPos = vtkContext2D::FloatToInt(origin + (this->TickPositions->GetValue(i) - this->Minimum) * scaling); this->TickScenePositions->InsertValue(i, iPos); - } + } this->BuildTime.Modified(); } @@ -309,57 +309,57 @@ bool vtkAxis::Paint(vtkContext2D *painter) this->UpdateLogScaleActive(false); if (!this->Visible) - { + { return false; - } + } this->GetBoundingRect(painter); painter->ApplyPen(this->Pen); // Draw this axis if (this->AxisVisible) - { + { painter->DrawLine(this->Point1[0], this->Point1[1], this->Point2[0], this->Point2[1]); - } + } // Draw the axis title if there is one if (!this->Title.empty()) - { + { int x = 0; int y = 0; painter->ApplyTextProp(this->TitleProperties); // Draw the axis label if (this->Position == vtkAxis::LEFT) - { + { // Draw the axis label x = vtkContext2D::FloatToInt(this->Point1[0] - this->MaxLabel[0] - 10); y = vtkContext2D::FloatToInt(this->Point1[1] + this->Point2[1]) / 2; - } + } else if (this->Position == vtkAxis::RIGHT) - { + { // Draw the axis label x = vtkContext2D::FloatToInt(this->Point1[0] + this->MaxLabel[0] + 10); y = vtkContext2D::FloatToInt(this->Point1[1] + this->Point2[1]) / 2; - } + } else if (this->Position == vtkAxis::BOTTOM) - { + { x = vtkContext2D::FloatToInt(this->Point1[0] + this->Point2[0]) / 2; y = vtkContext2D::FloatToInt(this->Point1[1] - this->MaxLabel[1] - 10); - } + } else if (this->Position == vtkAxis::TOP) - { + { x = vtkContext2D::FloatToInt(this->Point1[0] + this->Point2[0]) / 2; y = vtkContext2D::FloatToInt(this->Point1[1] + this->MaxLabel[1] + 10); - } + } else if (this->Position == vtkAxis::PARALLEL) - { + { x = vtkContext2D::FloatToInt(this->Point1[0]); y = vtkContext2D::FloatToInt(this->Point1[1] - this->MaxLabel[1] - 15); - } - painter->DrawString(x, y, this->Title); } + painter->DrawString(x, y, this->Title); + } // Now draw the tick marks painter->ApplyTextProp(this->LabelProperties); @@ -374,22 +374,22 @@ bool vtkAxis::Paint(vtkContext2D *painter) float labelOffset = this->LabelOffset; if (this->Position == vtkAxis::LEFT || this->Position == vtkAxis::PARALLEL || this->Position == vtkAxis::BOTTOM) - { + { // The other side of the axis line. tickLength *= -1.0; labelOffset *= -1.0; - } + } vtkVector2i tileScale(1); if (!this->Scene) - { + { vtkWarningMacro("vtkAxis needs a vtkContextScene to determine window " "properties. Assuming no tile scaling is set."); - } + } else - { + { tileScale = this->Scene->GetLogicalTileScale(); - } + } vtkRectf minLabelRect(0, 0, 0, 0); vtkRectf maxLabelRect(0, 0, 0, 0); @@ -398,7 +398,7 @@ bool vtkAxis::Paint(vtkContext2D *painter) // Optionally draw min/max labels if (this->RangeLabelsVisible) - { + { vtkStdString minString = this->GenerateSprintfLabel(this->UnscaledMinimum, this->RangeLabelFormat); vtkStdString maxString = this->GenerateSprintfLabel(this->UnscaledMaximum, this->RangeLabelFormat); @@ -411,33 +411,33 @@ bool vtkAxis::Paint(vtkContext2D *painter) // Compute where the string should go... if (this->Position == vtkAxis::LEFT || this->Position == vtkAxis::PARALLEL || this->Position == vtkAxis::RIGHT) - { + { minLabelShift[0] = this->Point1[0] + labelOffset; minLabelShift[1] = this->Point1[1]; maxLabelShift[0] = this->Point2[0] + labelOffset; maxLabelShift[1] = this->Point2[1]; if (this->TicksVisible) - { + { painter->DrawLine(this->Point1[0] + tickLength, this->Point1[1], this->Point1[0] , this->Point1[1]); painter->DrawLine(this->Point2[0] + tickLength, this->Point2[1], this->Point2[0] , this->Point2[1]); - } } + } else if (this->Position == vtkAxis::TOP || this->Position == vtkAxis::BOTTOM) - { + { minLabelShift[0] = this->Point1[0]; minLabelShift[1] = this->Point1[1] + labelOffset; maxLabelShift[0] = this->Point2[0]; maxLabelShift[1] = this->Point2[1] + labelOffset; if (this->TicksVisible) - { + { painter->DrawLine(this->Point1[0], this->Point1[1] + tickLength, this->Point1[0], this->Point1[1]); painter->DrawLine(this->Point2[0], this->Point2[1] + tickLength, this->Point2[0], this->Point2[1] ); - } } + } // Now draw the labels painter->DrawString(minLabelShift[0], minLabelShift[1], minString); @@ -459,29 +459,29 @@ bool vtkAxis::Paint(vtkContext2D *painter) maxLabelBounds[1] -= pad; maxLabelBounds[2] += 2*pad; maxLabelBounds[3] += 2*pad; - } + } // Horizontal or vertical axis. if (this->Position == vtkAxis::LEFT || this->Position == vtkAxis::PARALLEL || this->Position == vtkAxis::RIGHT) - { + { // Adptating tickLength and labelOffset to the tiling of the scene tickLength *= tileScale.GetX(); labelOffset *= tileScale.GetX(); // Draw the tick marks and labels for (vtkIdType i = 0; i < numMarks; ++i) - { + { // Skip any tick positions that are outside of the axis range. if (!this->InRange(this->TickPositions->GetValue(i))) - { + { continue; - } + } // Don't skip if range labels aren't visible bool skipTick = this->RangeLabelsVisible; if (this->LabelsVisible) - { + { float bounds[4]; painter->ComputeJustifiedStringBounds(tickLabel[i], bounds); float pos[2] = { this->Point1[0] + labelOffset, tickPos[i] }; @@ -491,21 +491,21 @@ bool vtkAxis::Paint(vtkContext2D *painter) vtkRectf boundsRect(bounds[0], bounds[1], bounds[2], bounds[3]); if (!boundsRect.IntersectsWith(minLabelRect) && !boundsRect.IntersectsWith(maxLabelRect)) - { + { painter->DrawString(pos[0], pos[1], tickLabel[i]); skipTick = false; - } } + } if (this->TicksVisible && !skipTick) - { + { painter->DrawLine(this->Point1[0] + tickLength, tickPos[i], this->Point1[0] , tickPos[i]); - } } } + } else if (this->Position == vtkAxis::TOP || this->Position == vtkAxis::BOTTOM) - { + { // Adptating tickLength and labelOffset to the tiling of the scene tickLength *= tileScale.GetY(); @@ -513,16 +513,16 @@ bool vtkAxis::Paint(vtkContext2D *painter) // Draw the tick marks and labels for (vtkIdType i = 0; i < numMarks; ++i) - { + { // Skip any tick positions that are outside of the axis range. if (!this->InRange(this->TickPositions->GetValue(i))) - { + { continue; - } + } bool skipTick = this->RangeLabelsVisible; if (this->LabelsVisible) - { + { float bounds[4]; painter->ComputeJustifiedStringBounds(tickLabel[i], bounds); float pos[2] = { tickPos[i], this->Point1[1] + labelOffset }; @@ -531,25 +531,25 @@ bool vtkAxis::Paint(vtkContext2D *painter) vtkRectf boundsRect(bounds[0], bounds[1], bounds[2], bounds[3]); if (!boundsRect.IntersectsWith(minLabelRect) && !boundsRect.IntersectsWith(maxLabelRect)) - { + { painter->DrawString(pos[0], pos[1], tickLabel[i]); skipTick = false; - } } + } if (this->TicksVisible && !skipTick) - { + { painter->DrawLine(tickPos[i], this->Point1[1] + tickLength, tickPos[i], this->Point1[1]); - } - } + } + } else - { + { vtkWarningMacro("Unknown position encountered in the paint call: " << this->Position); - } + } return true; } @@ -559,9 +559,9 @@ void vtkAxis::SetMinimum(double minimum) { minimum = std::max(minimum, this->MinimumLimit); if (this->Minimum == minimum) - { + { return; - } + } this->Minimum = minimum; this->UnscaledMinimum = this->LogScaleActive ? pow(10., this->Minimum) : this->Minimum; this->UsingNiceMinMax = false; @@ -575,9 +575,9 @@ void vtkAxis::SetUnscaledMinimum(double minimum) { minimum = std::max(minimum, this->UnscaledMinimumLimit); if (this->UnscaledMinimum == minimum) - { + { return; - } + } this->UnscaledMinimum = minimum; this->UpdateLogScaleActive(true); this->UsingNiceMinMax = false; @@ -590,46 +590,46 @@ void vtkAxis::SetUnscaledMinimum(double minimum) void vtkAxis::SetMinimumLimit(double lowest) { if (this->MinimumLimit == lowest) - { + { return; - } + } this->MinimumLimit = lowest; if (this->LogScaleActive) - { + { if (this->UnscaledMinimum < 0) - { + { this->UnscaledMaximumLimit = -1. * pow(10., this->MinimumLimit); - } + } else - { + { this->UnscaledMinimumLimit = pow(10., this->MinimumLimit); - } } + } else - { + { this->UnscaledMinimumLimit = this->MinimumLimit; - } + } if (this->Minimum < lowest) - { + { this->SetMinimum(lowest); - } + } } //----------------------------------------------------------------------------- void vtkAxis::SetUnscaledMinimumLimit(double lowest) { if (this->UnscaledMinimumLimit == lowest) - { + { return; - } + } this->UnscaledMinimumLimit = lowest; this->NonLogUnscaledMinLimit = this->UnscaledMinimumLimit; this->MinimumLimit = this->LogScaleActive ? log10(this->UnscaledMinimumLimit) : this->UnscaledMinimumLimit; if (this->UnscaledMinimum < lowest) - { + { this->SetUnscaledMinimum(lowest); - } + } } //----------------------------------------------------------------------------- @@ -637,9 +637,9 @@ void vtkAxis::SetMaximum(double maximum) { maximum = std::min(maximum, this->MaximumLimit); if (this->Maximum == maximum) - { + { return; - } + } this->Maximum = maximum; this->UnscaledMaximum = this->LogScaleActive ? pow(10., this->Maximum) : this->Maximum; this->UsingNiceMinMax = false; @@ -653,9 +653,9 @@ void vtkAxis::SetUnscaledMaximum(double maximum) { maximum = std::min(maximum, this->UnscaledMaximumLimit); if (this->UnscaledMaximum == maximum) - { + { return; - } + } this->UnscaledMaximum = maximum; this->UpdateLogScaleActive(true); this->UsingNiceMinMax = false; @@ -668,46 +668,46 @@ void vtkAxis::SetUnscaledMaximum(double maximum) void vtkAxis::SetMaximumLimit(double highest) { if (this->MaximumLimit == highest) - { + { return; - } + } this->MaximumLimit = highest; if (this->LogScaleActive) - { + { if (this->UnscaledMaximum < 0) - { + { this->UnscaledMinimumLimit = -1. * pow(10., this->MaximumLimit); - } + } else - { + { this->UnscaledMaximumLimit = pow(10., this->MaximumLimit); - } } + } else - { + { this->UnscaledMaximumLimit = this->MaximumLimit; - } + } if (this->Maximum > highest) - { + { this->SetMaximum(highest); - } + } } //----------------------------------------------------------------------------- void vtkAxis::SetUnscaledMaximumLimit(double highest) { if (this->UnscaledMaximumLimit == highest) - { + { return; - } + } this->UnscaledMaximumLimit = highest; this->NonLogUnscaledMaxLimit = this->UnscaledMaximumLimit; this->MaximumLimit = this->LogScaleActive ? log10(this->UnscaledMaximumLimit) : this->UnscaledMaximumLimit; if (this->UnscaledMaximum > highest) - { + { this->SetUnscaledMaximum(highest); - } + } } //----------------------------------------------------------------------------- @@ -721,10 +721,10 @@ void vtkAxis::SetRange(double minimum, double maximum) void vtkAxis::SetRange(double *range) { if (range) - { + { this->SetMinimum(range[0]); this->SetMaximum(range[1]); - } + } } //----------------------------------------------------------------------------- @@ -738,40 +738,40 @@ void vtkAxis::SetUnscaledRange(double minimum, double maximum) void vtkAxis::SetUnscaledRange(double *range) { if (range) - { + { this->SetUnscaledMinimum(range[0]); this->SetUnscaledMaximum(range[1]); - } + } } //----------------------------------------------------------------------------- void vtkAxis::GetRange(double *range) { if (range) - { + { range[0] = this->Minimum; range[1] = this->Maximum; - } + } } //----------------------------------------------------------------------------- void vtkAxis::GetUnscaledRange(double *range) { if (range) - { + { range[0] = this->UnscaledMinimum; range[1] = this->UnscaledMaximum; - } + } } //----------------------------------------------------------------------------- void vtkAxis::SetTitle(const vtkStdString &title) { if (this->Title != title) - { + { this->Title = title; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -784,9 +784,9 @@ vtkStdString vtkAxis::GetTitle() void vtkAxis::SetPrecision(int precision) { if (this->Precision == precision) - { + { return; - } + } this->Precision = precision; this->TickMarksDirty = true; this->Modified(); @@ -798,20 +798,20 @@ void vtkAxis::SetLabelFormat(const std::string &fmt) vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting LabelFormat to " << fmt); if (this->LabelFormat != fmt) - { + { this->LabelFormat = fmt; this->Modified(); this->TickMarksDirty = true; - } + } } //----------------------------------------------------------------------------- void vtkAxis::SetLogScale(bool logScale) { if (this->LogScale == logScale) - { + { return; - } + } this->LogScale = logScale; this->UpdateLogScaleActive(false); this->Modified(); @@ -821,9 +821,9 @@ void vtkAxis::SetLogScale(bool logScale) void vtkAxis::SetNotation(int notation) { if (this->Notation == notation) - { + { return; - } + } this->Notation = notation; this->TickMarksDirty = true; this->Modified(); @@ -833,19 +833,19 @@ void vtkAxis::SetNotation(int notation) void vtkAxis::AutoScale() { if (this->Behavior != vtkAxis::AUTO) - { + { return; - } + } this->UpdateLogScaleActive(false); // Calculate the min and max, set the number of ticks and the tick spacing. if (this->TickLabelAlgorithm == vtkAxis::TICK_SIMPLE) - { + { double min = this->Minimum; double max = this->Maximum; this->TickInterval = this->CalculateNiceMinMax(min, max); this->SetRange(min, max); - } + } this->UsingNiceMinMax = true; this->GenerateTickLabels(this->Minimum, this->Maximum); } @@ -856,56 +856,56 @@ void vtkAxis::RecalculateTickSpacing() // Calculate the min and max, set the number of ticks and the tick spacing, // discard the min and max in this case. TODO: Refactor the function called. if (this->Behavior == vtkAxis::AUTO || this->Behavior == vtkAxis::FIXED) - { + { double min = this->Minimum; double max = this->Maximum; if (this->TickLabelAlgorithm == vtkAxis::TICK_SIMPLE) - { + { this->TickInterval = this->CalculateNiceMinMax(min, max); - } + } if (this->UsingNiceMinMax) - { + { this->GenerateTickLabels(this->Minimum, this->Maximum); - } + } else if (this->TickInterval == -1.0) - { + { // if axis do not have a valid tickinterval - return return; - } + } else - { + { // Calculated tickinterval may be 0. So calculation of new minimum and // maximum by incrementing/decrementing using tickinterval will fail. if (this->TickInterval == 0.0) - { + { return; - } + } if (this->Minimum < this->Maximum) - { + { while (min < this->Minimum) - { + { min += this->TickInterval; - } + } while (max > this->Maximum) - { + { max -= this->TickInterval; - } } + } else - { + { while (min > this->Minimum) - { + { min -= this->TickInterval; - } + } while (max < this->Maximum) - { + { max += this->TickInterval; - } } - this->GenerateTickLabels(min, max); } + this->GenerateTickLabels(min, max); } + } } //----------------------------------------------------------------------------- @@ -931,40 +931,40 @@ bool vtkAxis::SetCustomTickPositions(vtkDoubleArray *positions, vtkStringArray *labels) { if (!positions && !labels) - { + { this->CustomTickLabels = false; this->TickMarksDirty = true; this->TickPositions->SetNumberOfTuples(0); this->TickLabels->SetNumberOfTuples(0); this->Modified(); return true; - } + } else if (positions && !labels) - { + { this->TickPositions->DeepCopy(positions); this->TickLabels->SetNumberOfTuples(0); this->CustomTickLabels = true; this->TickMarksDirty = false; this->Modified(); return true; - } + } else if (positions && labels) - { + { if (positions->GetNumberOfTuples() != labels->GetNumberOfTuples()) - { + { return false; - } + } this->TickPositions->DeepCopy(positions); this->TickLabels->DeepCopy(labels); this->CustomTickLabels = true; this->TickMarksDirty = false; this->Modified(); return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -973,28 +973,28 @@ vtkRectf vtkAxis::GetBoundingRect(vtkContext2D* painter) bool vertical = false; if (this->Position == vtkAxis::LEFT || this->Position == vtkAxis::RIGHT || this->Position == vtkAxis::PARALLEL) - { + { vertical = true; - } + } // First, calculate the widest tick label float widest = 0.0; // Second, calculate the tallest tick label float tallest = 0.0; vtkRectf bounds(0, 0, 0, 0); if (this->LabelsVisible) - { + { for(vtkIdType i = 0; i < this->TickLabels->GetNumberOfTuples(); ++i) - { + { painter->ApplyTextProp(this->LabelProperties); painter->ComputeStringBounds(this->TickLabels->GetValue(i), bounds.GetData()); widest = bounds.GetWidth() > widest ? bounds.GetWidth() : widest; tallest = bounds.GetHeight() > tallest ? bounds.GetHeight() : tallest; - } } + } if (this->RangeLabelsVisible) - { + { // Add in the range labels vtkStdString minLabel = this->GenerateSprintfLabel(this->UnscaledMinimum, this->RangeLabelFormat); vtkStdString maxLabel = this->GenerateSprintfLabel(this->UnscaledMaximum, this->RangeLabelFormat); @@ -1006,7 +1006,7 @@ vtkRectf vtkAxis::GetBoundingRect(vtkContext2D* painter) painter->ComputeStringBounds(maxLabel, bounds.GetData()); widest = bounds.GetWidth() > widest ? bounds.GetWidth() : widest; tallest = bounds.GetHeight() > tallest ? bounds.GetHeight() : tallest; - } + } this->MaxLabel[0] = widest; this->MaxLabel[1] = tallest; @@ -1014,26 +1014,26 @@ vtkRectf vtkAxis::GetBoundingRect(vtkContext2D* painter) // Then, if there is an axis label, add that in. vtkRectf titleBounds(0, 0, 0, 0); if (this->Title && !this->Title.empty()) - { + { painter->ApplyTextProp(this->TitleProperties); painter->ComputeStringBounds(this->Title, titleBounds.GetData()); - } + } if (vertical) - { + { bounds.SetWidth(widest + titleBounds.GetWidth() + this->Margins[0]); float range = this->Point1[1] < this->Point2[1] ? this->Point2[1] - this->Point1[1] : this->Point1[1] - this->Point2[1]; bounds.SetHeight(range + tallest + this->Margins[1]); - } + } else - { + { bounds.SetHeight(tallest + titleBounds.GetHeight() + this->Margins[0]); float range = this->Point1[0] < this->Point2[0] ? this->Point2[0] - this->Point1[0] : this->Point1[0] - this->Point2[0]; bounds.SetWidth(range + widest + this->Margins[1]); - } + } return bounds; } @@ -1043,66 +1043,66 @@ void vtkAxis::UpdateLogScaleActive(bool alwaysUpdateMinMaxFromUnscaled) bool needUpdate = false; if (this->LogScale && this->UnscaledMinimum * this->UnscaledMaximum > 0.) - { + { if (!this->LogScaleActive) - { + { this->LogScaleActive = true; this->TickMarksDirty = true; needUpdate = true; - } + } if (needUpdate || alwaysUpdateMinMaxFromUnscaled) - { + { if (this->UnscaledMinimum < 0) - { // Both unscaled min & max are negative, logs must be swapped + { // Both unscaled min & max are negative, logs must be swapped this->Minimum = log10(fabs(this->UnscaledMaximum)); this->Maximum = log10(fabs(this->UnscaledMinimum)); if (this->UnscaledMaximumLimit >= 0) - { + { // The limit is on the other side of 0 relative to the data... // move it to the same side as the data. // Specifically, allow scrolling equal to the width of the plot. this->MinimumLimit = -vtkMath::Inf(); this->NonLogUnscaledMaxLimit = this->UnscaledMaximumLimit; this->UnscaledMaximumLimit = 0.; - } + } else - { + { this->MinimumLimit = log10(fabs(this->UnscaledMaximumLimit)); - } - this->MaximumLimit = log10(fabs(this->UnscaledMinimumLimit)); } + this->MaximumLimit = log10(fabs(this->UnscaledMinimumLimit)); + } else - { + { this->Minimum = log10(fabs(this->UnscaledMinimum)); this->Maximum = log10(fabs(this->UnscaledMaximum)); if (this->UnscaledMinimumLimit <= 0) - { + { // The limit is on the other side of 0 relative to the data... // move it to the same side as the data. // Specifically, allow scrolling equal to the width of the plot. this->MinimumLimit = -vtkMath::Inf(); this->NonLogUnscaledMinLimit = this->UnscaledMinimumLimit; this->UnscaledMinimumLimit = 0.; - } + } else - { + { this->MinimumLimit = log10(fabs(this->UnscaledMinimumLimit)); - } - this->MaximumLimit = log10(fabs(this->UnscaledMaximumLimit)); } - this->Modified(); + this->MaximumLimit = log10(fabs(this->UnscaledMaximumLimit)); } + this->Modified(); } + } else - { + { if (this->LogScaleActive) - { + { this->LogScaleActive = false; this->TickMarksDirty = true; needUpdate = true; - } + } if (needUpdate || alwaysUpdateMinMaxFromUnscaled) - { + { this->Minimum = this->UnscaledMinimum; this->Maximum = this->UnscaledMaximum; this->UnscaledMinimumLimit = this->NonLogUnscaledMinLimit; @@ -1110,18 +1110,18 @@ void vtkAxis::UpdateLogScaleActive(bool alwaysUpdateMinMaxFromUnscaled) this->MinimumLimit = this->UnscaledMinimumLimit; this->MaximumLimit = this->UnscaledMaximumLimit; this->Modified(); - } } + } } //----------------------------------------------------------------------------- void vtkAxis::GenerateTickLabels(double min, double max) { if (this->CustomTickLabels == true) - { + { // Never generate new tick labels if custom tick labels are being used. return; - } + } // Now calculate the tick labels, and positions within the axis range this->TickPositions->SetNumberOfTuples(0); this->TickLabels->SetNumberOfTuples(0); @@ -1129,7 +1129,7 @@ void vtkAxis::GenerateTickLabels(double min, double max) // We generate a logarithmic scale when logarithmic axis is activated and the // order of magnitude of the axis is higher than 0.6. if (this->LogScaleActive) - { + { // We calculate the first tick mark for lowest order of magnitude. // and the last for the highest order of magnitude. this->TickInterval = this->CalculateNiceMinMax(min, max); @@ -1148,35 +1148,35 @@ void vtkAxis::GenerateTickLabels(double min, double max) // We generate the tick marks for all orders of magnitude if (maxOrder - minOrder == 0) - { + { this->GenerateLogSpacedLinearTicks(minOrder, min, max); - } + } else - { + { if (maxOrder - minOrder + 1 > 5) - { + { GenerateLogScaleTickMarks(minOrder, minValue, 9.0, false); for(int i = minOrder + 1; i < maxOrder; ++i) - { + { GenerateLogScaleTickMarks(i, 1.0, 9.0, false); - } - GenerateLogScaleTickMarks(maxOrder, 1.0, maxValue, false); } + GenerateLogScaleTickMarks(maxOrder, 1.0, maxValue, false); + } else - { + { GenerateLogScaleTickMarks(minOrder, minValue, 9.0); for(int i = minOrder + 1; i < maxOrder; ++i) - { + { GenerateLogScaleTickMarks(i, 1.0, 9.0); - } - GenerateLogScaleTickMarks(maxOrder, 1.0, maxValue); } + GenerateLogScaleTickMarks(maxOrder, 1.0, maxValue); } } + } else - { + { if (this->TickLabelAlgorithm == vtkAxis::TICK_WILKINSON_EXTENDED) - { + { // Now calculate the tick labels, and positions within the axis range //This gets the tick interval and max, min of labeling from the Extended // algorithm @@ -1185,24 +1185,24 @@ void vtkAxis::GenerateTickLabels(double min, double max) // When the axis is not initialized if(this->Point1[0] == 0 && this->Point2[0] == 0) - { + { // 500 is an initial guess for the length of the axis in pixels scaling = 500 / (this->Maximum - this->Minimum); - } + } else - { + { if (this->Point1[0] == this->Point2[0]) // x1 == x2, therefore vertical - { + { scaling = (this->Point2[1] - this->Point1[1]) / (this->Maximum - this->Minimum); axisVertical = true; - } + } else - { + { scaling = (this->Point2[0] - this->Point1[0]) / (this->Maximum - this->Minimum); - } } + } int fontSize = this->LabelProperties->GetFontSize(); vtkNew tickPositionExtended; @@ -1222,89 +1222,89 @@ void vtkAxis::GenerateTickLabels(double min, double max) this->TickInterval = values[2]; if(min < this->Minimum) - { + { this->Minimum = min; this->UnscaledMinimum = (this->LogScaleActive ? pow(10., this->Minimum) : this->Minimum); - } + } if(max > this->Maximum) - { + { this->Maximum = max; this->UnscaledMaximum = (this->LogScaleActive ? pow(10., this->Maximum) : this->Maximum); - } + } this->Notation = tickPositionExtended->GetLabelFormat(); this->LabelProperties->SetFontSize(tickPositionExtended->GetFontSize()); if(tickPositionExtended->GetOrientation() == 1) - { + { // Set this to 90 to make the labels vertical this->LabelProperties->SetOrientation(90); - } } + } double mult = max > min ? 1.0 : -1.0; double range = 0.0; int n = 0; if (this->LogScaleActive) - { + { range = mult > 0.0 ? pow(10.0, max) - pow(10.0, min) : pow(10.0, min) - pow(10.0, max); n = vtkContext2D::FloatToInt(range / pow(10.0, this->TickInterval)); - } + } else if (this->NumberOfTicks >= 0) - { + { n = this->NumberOfTicks - 1; - } + } else - { + { range = mult > 0.0 ? max - min : min - max; n = vtkContext2D::FloatToInt(range / this->TickInterval); - } + } for (int i = 0; i <= n && i < 200; ++i) - { + { double value = 0.0; if (this->LogScaleActive) - { + { value = log10(pow(10.0, min) + double(i) * mult * pow(10.0, this->TickInterval)); - } + } else - { + { value = min + double(i) * mult * this->TickInterval; - } + } if (this->TickInterval < 1.0) - { + { // For small TickInterval, increase the precision of the comparison if (fabs(value) < (0.00000001 * this->TickInterval)) - { + { value = 0.0; - } } + } else - { + { if (fabs(value) < 0.00000001) - { + { value = 0.0; - } } + } this->TickPositions->InsertNextValue(value); // Make a tick mark label for the tick if (this->LogScaleActive) - { + { value = pow(double(10.0), double(value)); - } + } // Now create a label for the tick position if (this->TickLabelAlgorithm == vtkAxis::TICK_SIMPLE) - { + { this->TickLabels->InsertNextValue(this->GenerateSimpleLabel(value)); - } + } else - { + { // The following call inserts a label into this->TickLabels this->GenerateLabelFormat(this->Notation, value); - } } - } + + } this->TickMarksDirty = false; } @@ -1313,15 +1313,15 @@ void vtkAxis::GenerateTickLabels() { this->TickLabels->SetNumberOfTuples(0); for (vtkIdType i = 0; i < this->TickPositions->GetNumberOfTuples(); ++i) - { + { double value = this->TickPositions->GetValue(i); // Make a tick mark label for the tick if (this->LogScaleActive) - { + { value = pow(double(10.0), double(value)); - } - this->TickLabels->InsertNextValue(this->GenerateSimpleLabel(value)); } + this->TickLabels->InsertNextValue(this->GenerateSimpleLabel(value)); + } } //----------------------------------------------------------------------------- @@ -1329,45 +1329,45 @@ vtkStdString vtkAxis::GenerateSimpleLabel(double val) { vtkStdString result; if (this->Notation == PRINTF_NOTATION) - { // Use the C-style printf specification: + { // Use the C-style printf specification: result = this->GenerateSprintfLabel(val, this->LabelFormat); - } + } else - { // Use the C++ style stream format specification: + { // Use the C++ style stream format specification: std::ostringstream ostr; ostr.imbue(std::locale::classic()); if (this->Notation != STANDARD_NOTATION) - { + { ostr.precision(this->Precision); if (this->Notation == SCIENTIFIC_NOTATION) - { + { ostr.setf(std::ios::scientific, std::ios::floatfield); - } + } else if (this->Notation == FIXED_NOTATION) - { + { ostr.setf(ios::fixed, ios::floatfield); - } } + } ostr << val; result = vtkStdString(ostr.str()); - } + } // Strip out leading zeros on the exponent: vtksys::RegularExpression regExp("[Ee][+-]"); if (regExp.find(result)) - { + { vtkStdString::iterator it = result.begin() + regExp.start() + 2; while (it != result.end() && *it == '0') - { + { it = result.erase(it); - } + } // If the exponent is 0, remove the e+ bit, too. if (it == result.end()) - { + { result.erase(regExp.start()); - } } + } return result; } @@ -1388,7 +1388,7 @@ void vtkAxis::GenerateLabelFormat(int notation, double n) ostr.imbue(std::locale::classic()); switch(notation) - { + { case 1: ostr << n; ostr.precision(this->Precision); @@ -1398,41 +1398,41 @@ void vtkAxis::GenerateLabelFormat(int notation, double n) case 2: ostr << n; if((std::ceil(n)-std::floor(n)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } this->TickLabels->InsertNextValue(ostr.str()); break; case 3: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000.0 << "K"; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } this->TickLabels->InsertNextValue(ostr.str()); // minus three zeros + K break; case 4: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000.0 ; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } if(!TitleAppended) - { + { this->Title.append(" (K)"); TitleAppended = true; - } + } this->TickLabels->InsertNextValue(ostr.str());// minus three zeros break; case 5: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000000.0 << "M"; if((std::ceil(n/1000000.0)-std::floor(n/1000000.0)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } this->TickLabels->InsertNextValue(ostr.str()); // minus six zeros break; case 6: @@ -1440,14 +1440,14 @@ void vtkAxis::GenerateLabelFormat(int notation, double n) ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000000.0; if((std::ceil(n/1000000.0)-std::floor(n/1000000.0)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } if(!TitleAppended) - { + { this->Title.append(" (M)"); TitleAppended = true; - } + } this->TickLabels->InsertNextValue(ostr.str()); // minus six zeros + M break; case 7: @@ -1455,14 +1455,14 @@ void vtkAxis::GenerateLabelFormat(int notation, double n) ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000.0; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0 ) - { + { ostr.precision(this->Precision); - } + } if(!TitleAppended) - { + { this->Title.append(" ('000)"); TitleAppended = true; - } + } this->TickLabels->InsertNextValue(ostr.str()); // Three 0's get reduced break; case 8: @@ -1470,13 +1470,13 @@ void vtkAxis::GenerateLabelFormat(int notation, double n) ostr.setf(std::ios::scientific, std::ios::floatfield); ostr << n/1000.0 ; if(!TitleAppended) - { + { this->Title.append(" ('000)"); TitleAppended = true; - } + } this->TickLabels->InsertNextValue(ostr.str()); break; - } + } } //----------------------------------------------------------------------------- @@ -1511,40 +1511,40 @@ double vtkAxis::NiceMinMax(double &min, double &max, float pixelRange, { // First get the order of the range of the numbers if (min == max) - { + { if (fabs(min) < 1e-70 && fabs(max) < 1e-70) - { + { min = -0.0000001; max = 0.0000001; - } + } else - { + { min *= 0.95; max *= 1.05; - } } + } else if ((max - min) < 1.0e-60) - { + { min *= 0.95; max *= 1.05; - } + } double range = max - min; bool isNegative = false; if (range < 0.0f) - { + { isNegative = true; range *= -1.0f; - } + } // Calculate an upper limit on the number of tick marks - at least 30 pixels // should be between each tick mark. int maxTicks = vtkContext2D::FloatToInt(pixelRange / tickPixelSpacing); if (maxTicks == 0) - { + { // The axes do not have a valid set of points - return return -1.0f; - } + } double tickSpacing = range / maxTicks; int order = static_cast(floor(log10(tickSpacing))); @@ -1553,15 +1553,15 @@ double vtkAxis::NiceMinMax(double &min, double &max, float pixelRange, niceTickSpacing *= pow(double(10.0), order); if (isNegative) - { + { min = ceil(min / niceTickSpacing) * niceTickSpacing; max = floor(max / niceTickSpacing) * niceTickSpacing; - } + } else - { + { min = floor(min / niceTickSpacing) * niceTickSpacing; max = ceil(max / niceTickSpacing) * niceTickSpacing; - } + } return niceTickSpacing; } @@ -1570,50 +1570,50 @@ double vtkAxis::NiceMinMax(double &min, double &max, float pixelRange, double vtkAxis::CalculateNiceMinMax(double &min, double &max) { if (this->NumberOfTicks > 0) - { + { // An exact number of ticks was requested, use the min/max and exact number. min = this->Minimum; max = this->Maximum; double range = fabs(max - min); return range / double(this->NumberOfTicks - 1); - } + } vtkVector2i tileScale(1); if (!this->Scene) - { + { vtkWarningMacro("vtkAxis needs a vtkContextScene to determine window " "properties. Assuming no tile scaling is set."); - } + } else - { + { tileScale = this->Scene->GetLogicalTileScale(); - } + } float pixelRange = 0; float tickPixelSpacing = 0; if (this->Position == vtkAxis::LEFT || this->Position == vtkAxis::RIGHT || this->Position == vtkAxis::PARALLEL) - { + { pixelRange = this->Position2.GetY() - this->Position1.GetY(); tickPixelSpacing = 30 * tileScale.GetX(); - } + } else - { + { pixelRange = this->Position2.GetX() - this->Position1.GetX(); tickPixelSpacing = 45 * tileScale.GetY(); - } + } double niceTickSpacing = 0.0; if (max < min) - { + { niceTickSpacing = vtkAxis::NiceMinMax(max, min, pixelRange, tickPixelSpacing); - } + } else - { + { niceTickSpacing = vtkAxis::NiceMinMax(min, max, pixelRange, tickPixelSpacing); - } + } return niceTickSpacing; } @@ -1622,43 +1622,43 @@ double vtkAxis::CalculateNiceMinMax(double &min, double &max) double vtkAxis::NiceNumber(double n, bool roundUp) { if (roundUp) - { + { if (n <= 1.0) - { + { return 1.0; - } + } else if (n <= 2.0) - { + { return 2.0; - } + } else if (n <= 5.0) - { + { return 5.0; - } + } else - { + { return 10.0; - } } + } else - { + { if (n < 1.5) - { + { return 1.0; - } + } else if (n <= 3.0) - { + { return 2.0; - } + } else if (n <= 7.0) - { + { return 5.0; - } + } else - { + { return 10.0; - } } + } } //----------------------------------------------------------------------------- @@ -1678,9 +1678,9 @@ double vtkAxis::LogScaleTickMark(double number, // If result is 1.0, 2.0 or 5.0 we mark the result as "nice value". niceValue = false; if (result == 1.0 || result == 2.0 || result == 5.0) - { + { niceValue = true; - } + } return result; } @@ -1694,26 +1694,26 @@ void vtkAxis::GenerateLogSpacedLinearTicks(int order, double min, double max) double linMax = pow(10., max); int varyDigit = static_cast(floor(log10(linMax - linMin))); if (varyDigit == order) - { + { --varyDigit; - } + } double multiplier = pow(10.,varyDigit); int lo = static_cast(floor(linMin / multiplier)); int hi = static_cast(ceil(linMax / multiplier)); if (hi - lo < 2) - { + { ++hi; --lo; - } + } int incr = 1; int nt = hi - lo; if (nt > 20) - { + { incr = nt > 10 ? 5 : 2; - } + } for(int j = lo; j <= hi; j += incr) - { + { // We calculate the tick mark value double value = j * multiplier; this->TickPositions->InsertNextValue(log10(value)); @@ -1722,21 +1722,21 @@ void vtkAxis::GenerateLogSpacedLinearTicks(int order, double min, double max) std::ostringstream ostr; ostr.imbue(std::locale::classic()); if (this->Notation > 0) - { + { ostr.precision(this->Precision); - } + } if (this->Notation == SCIENTIFIC_NOTATION) - { + { ostr.setf(std::ios::scientific, std::ios::floatfield); - } + } else if (this->Notation == FIXED_NOTATION) - { + { ostr.setf(ios::fixed, ios::floatfield); - } + } ostr << value; this->TickLabels->InsertNextValue(ostr.str()); - } + } } //----------------------------------------------------------------------------- @@ -1747,26 +1747,26 @@ void vtkAxis::GenerateLogScaleTickMarks(int order, { // If the values min and max are not within limits we set defaults if (min < 1.0) - { + { min = 1.0; - } + } if (min > 9.0) - { + { min = 1.0; - } + } if (max < 1.0) - { + { max = 9.0; - } + } if (max > 9.0) - { + { max = 9.0; - } + } if (fabs(max-min) < 1.0) - { + { min = 1.0; max = 9.0; - } + } // Make sure we have integers int minimum = static_cast(ceil(min)); @@ -1774,32 +1774,32 @@ void vtkAxis::GenerateLogScaleTickMarks(int order, double result(minimum); for(int j = minimum; j <= maximum; ++j) - { + { // We check if tick mark is getting an label depending on detailLabels bool niceTickMark = false; if (detailLabels) - { + { niceTickMark = (result == 1.0 || result == 2.0 || result == 5.0); - } + } else - { + { niceTickMark = (result == 1.0); - } + } // We calculate the tick mark value double value = result * pow(10.0, static_cast(order)); this->TickPositions->InsertNextValue(log10(value)); if (niceTickMark) - { + { this->TickLabels->InsertNextValue(this->GenerateSimpleLabel(value)); - } + } else - { + { this->TickLabels->InsertNextValue(""); - } - result += 1.0; } + result += 1.0; + } } //----------------------------------------------------------------------------- @@ -1809,18 +1809,18 @@ inline bool vtkAxis::InRange(double value) double min(this->Minimum); double max(this->Maximum); if (min > max) - { + { min = max; max = this->Minimum; - } + } if (value < min || value > max) - { + { return false; - } + } else - { + { return true; - } + } } //----------------------------------------------------------------------------- @@ -1828,9 +1828,9 @@ void vtkAxis::PrintSelf(ostream &os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); if (this->Title) - { + { os << indent << "Axis title: \"" << *this->Title << "\"" << endl; - } + } os << indent << "Minimum point: " << this->Point1[0] << ", " << this->Point1[1] << endl; os << indent << "Maximum point: " << this->Point2[0] << ", " @@ -1849,7 +1849,7 @@ void vtkAxis::PrintSelf(ostream &os, vtkIndent indent) os << indent << "Precision: " << this->Precision << endl; os << indent << "Notation: "; switch (this->Notation) - { + { case STANDARD_NOTATION: os << "STANDARD_NOTATION"; break; @@ -1869,12 +1869,12 @@ void vtkAxis::PrintSelf(ostream &os, vtkIndent indent) default: os << ""; break; - } + } os << endl; os << indent << "LabelFormat: " << this->LabelFormat << endl; os << indent << "Behavior: "; switch (this->Behavior) - { + { case AUTO: os << "AUTO"; break; @@ -1890,7 +1890,7 @@ void vtkAxis::PrintSelf(ostream &os, vtkIndent indent) default: os << ""; break; - } + } os << endl; os << indent << "Unscaled range: " diff --git a/Charts/Core/vtkAxisExtended.cxx b/Charts/Core/vtkAxisExtended.cxx index 6ae93df2332..6fdfc149feb 100644 --- a/Charts/Core/vtkAxisExtended.cxx +++ b/Charts/Core/vtkAxisExtended.cxx @@ -52,13 +52,13 @@ double vtkAxisExtended::Simplicity(int qIndex, int qLength, int j, double lmin, double rem = fmod(lmin,lstep); if((rem < eps || (lstep - rem ) < eps ) && lmin <= 0 && lmax >= 0) - { + { v = 0; - } + } else - { + { v = 1; // v is 1 is lebelling includes zero - } + } return 1.0 - (qIndex - 1.0) / (qLength - 1.0) - j + v; } @@ -88,14 +88,14 @@ double vtkAxisExtended::CoverageMax(double dmin, double dmax, double span) { double range = dmax - dmin; if (span > range) - { + { double half = (span - range)/2; return 1- 0.5 * (pow(half, 2) + pow(half, 2) / pow(0.1*(range),2)); - } + } else - { + { return 1.0; - } + } } // This method return a value to make the density of the labels close to the @@ -114,13 +114,13 @@ double vtkAxisExtended::Density(int k, double m, double dmin, double dmax, double vtkAxisExtended::DensityMax(int k, double m) { if(k >= m) - { + { return 2 - (k-1) / (m-1); - } + } else - { + { return 1; - } + } } // This methods gives a weighing factor for each label depending on the range @@ -136,61 +136,61 @@ double vtkAxisExtended::DensityMax(int k, double m) double vtkAxisExtended::FormatLegibilityScore(double n, int format) { switch(format) - { + { case 1: return 0.25; case 2: if(std::abs(n) > 0.0001 && std::abs(n) < 1000000) - { + { return 1.0; - } + } else - { + { return 0.0; - } + } case 3: if(std::abs(n) > 1000 && std::abs(n) < 1000000) - { + { return 0.75; - } + } else - { + { return 0.0; - } + } case 4: if(std::abs(n) > 1000 && std::abs(n) < 1000000) - { + { return 0.4; - } + } else - { + { return 0.0; - } + } case 5: if(std::abs(n) > 1000000 && std::abs(n) < 1000000000) - { + { return 0.75; - } + } else - { + { return 0.0; - } + } case 6: if(std::abs(n) > 1000000 && std::abs(n) < 1000000000) - { + { return 0.4; - } + } else - { + { return 0.0; - } + } case 7: return 0.5; case 8: return 0.3; default: return 0.0; - } + } } @@ -202,7 +202,7 @@ int vtkAxisExtended::FormatStringLength(int format, double n, int precision) int numSize(0); switch(format) - { + { case 1: ostr.precision(precision); ostr.setf(std::ios::scientific, std::ios::floatfield); @@ -212,9 +212,9 @@ int vtkAxisExtended::FormatStringLength(int format, double n, int precision) case 2: ostr << n; if((std::ceil(n)-std::floor(n)) != 0.0 ) - { + { ostr.precision(precision); - } + } // Gets the length of the string with the current format without the end // character numSize = (int) ostr.str().length()-1; @@ -223,45 +223,45 @@ int vtkAxisExtended::FormatStringLength(int format, double n, int precision) ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0 ) - { + { ostr.precision(precision); - } + } numSize = (int) ostr.str().length()-1; return numSize+1; // minus three zeros + K case 4: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0) - { + { ostr.precision(precision); - } + } numSize = static_cast(ostr.str().length() - 1); return numSize; // minus three zeros case 5: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000000; if((std::ceil(n/1000000.0) - std::floor(n/1000000.0)) != 0.0) - { + { ostr.precision(precision); - } + } numSize = (int) ostr.str().length()-1; return numSize; // minus six zeros case 6: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000000; if((std::ceil(n/1000000.0)-std::floor(n/1000000.0)) != 0.0 ) - { + { ostr.precision(precision); - } + } numSize = (int) ostr.str().length()-1; return numSize+1; // minus six zeros + M case 7: ostr.setf(ios::fixed, ios::floatfield); ostr << n/1000; if((std::ceil(n/1000.0)-std::floor(n/1000.0)) != 0.0 ) - { + { ostr.precision(precision); - } + } numSize = (int) ostr.str().length()-1; return numSize; // Three 0's get reduced case 8: @@ -272,7 +272,7 @@ int vtkAxisExtended::FormatStringLength(int format, double n, int precision) return numSize; default: return 0; - } + } } // This methods determines the optimum notation, font size and orientation of @@ -285,9 +285,9 @@ double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep, double* tickPositions = new double[numTicks]; int fontSizes[8] = { 8, 9, 10, 12, 14, 18, 20, 24 }; for(int i = 0; i< numTicks; ++i) - { + { tickPositions[i] = lmax + i*lstep; - } + } // this->LabelLegibilityChanged = true; int bestFormat = 1; @@ -297,12 +297,12 @@ double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep, double bestLegScore = 0.0; for(int iFormat = 1; iFormat < 9; ++iFormat) - { + { double formatLegSum = 0.0; for(int i = 0; i=0) - { + { v = 0; - } + } else - { + { v = 1; // v is 1 is lebelling includes zero - } + } formatLegSum = 0.9 * formatLegSum + 0.1 * v; @@ -325,25 +325,25 @@ double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep, // 8 font sizes are checked for (int fontIndex = 0; fontIndex < 8 ; ++fontIndex) - { + { int iFont = fontSizes[fontIndex]; if(iFont == this->DesiredFontSize) - { + { fontLegSum = 1.0; - } + } // fontSizes[0] is the minimum font size else if ( iFontDesiredFontSize && iFont >= fontSizes[0]) - { + { fontLegSum = 0.2 * (iFont - fontSizes[0] + 1) / (this->DesiredFontSize - fontSizes[0]); - } + } else - { + { fontLegSum = -100.0; - } + } for(int iOrientation = 0 ; iOrientation <2 ; ++iOrientation) - { + { double orientLegSum = (iOrientation == 0) ? 1 : -0.5; // Here the gap between two consecutive labels is calculated as: // 2*Actual distance (in pixels) among two ticks - string lengths of @@ -353,23 +353,23 @@ double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep, double legScore = (formatLegSum + fontLegSum + orientLegSum + overlapLegSum) / 4; if(legScore > bestLegScore ) - { + { if(numTicks>1) - { + { double fontExtent; if((this->IsAxisVertical && iOrientation) || (!this->IsAxisVertical && !iOrientation) ) - { + { fontExtent = (FormatStringLength(iFormat,tickPositions[numTicks-1], this->Precision) + FormatStringLength(iFormat,tickPositions[numTicks-2], this->Precision))*iFont; - } + } else - { + { fontExtent = iFont * 2; - } + } double tickDistance = lstep * scaling; double labelingGap= 2*(tickDistance) - fontExtent; // 1.1 for line spacing @@ -386,22 +386,22 @@ double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep, { overlapLegSum = -100; }*/ - } + } legScore = (formatLegSum + fontLegSum + orientLegSum + overlapLegSum)/4; if ( legScore > bestLegScore) - { + { bestFormat = iFormat; bestOrientation = iOrientation; bestFontSize = iFont; bestLegScore = legScore; - } } } } } + } parameters[0] = bestFormat; parameters[1] = bestFontSize; @@ -422,18 +422,18 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin, this->LabelLegibilityChanged = false; if(dmin > dmax) - { + { double temp = dmin; dmin = dmax; dmax = temp; - } + } if( dmax - dmin < eps) - { + { ans[0] = dmin; ans[1]= dmax; ans[2]= m; //return Sequence(dmin,dmax, m); return ans; - } + } int qLength = 6;//Q.Length(); // Hard Coded @@ -445,46 +445,46 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin, int j = 1; while(j < INF) - { + { for(int qIndex = 0; qIndex < qLength; ++qIndex) - { + { double sm = SimplicityMax(qIndex, qLength, j); if((w[0]*sm + w[1] + w[2] + w[3]) < bestScore) - { + { j = INF; break; - } + } int k = 2; while(k < INF) - { + { double dm = DensityMax(k,m); if((w[0]*sm + w[1] + w[2]*dm + w[3]) < bestScore) - { + { break; - } + } double delta = (dmax- dmin)/((k+1)*j*Q[qIndex]) ; double z = ceil(log10(delta)); while(z < INF) - { + { double step = j*Q[qIndex]*pow(10.0,z); //double cm = CoverageMax(dmin, dmax, step*(k-1)); if((w[0]*sm + w[1] + w[2]*dm + w[3]) < bestScore) - { + { break; - } + } int minStart = static_cast(std::floor(dmax / step) * j - (k-1) * j); int maxStart = static_cast(std::ceil(dmin/step) * j); if(minStart > maxStart) - { + { ++z; continue; - } + } for(int start = minStart; start <= maxStart; ++start) - { + { double lmin = start * (step/j); double lmax = lmin + step*(k-1); double lstep = step; @@ -507,7 +507,7 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin, score = w[0] * s + w[1] * c + w[2] * g + w[3] * newScore; if(score > bestScore) - { + { bestScore = score; bestLmin = lmin; bestLmax = lmax; @@ -515,15 +515,15 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin, this->LabelFormat = legibilityIndex[0]; // label format this->FontSize = legibilityIndex[1]; // label font size this->Orientation = legibilityIndex[2]; // label orientation - } } - ++z; } - ++k; + ++z; } + ++k; } - ++j; } + ++j; + } ans[0] = bestLmin; ans[1] = bestLmax; ans[2] = bestLstep; diff --git a/Charts/Core/vtkCategoryLegend.cxx b/Charts/Core/vtkCategoryLegend.cxx index dfde383ddca..04f8433c43c 100644 --- a/Charts/Core/vtkCategoryLegend.cxx +++ b/Charts/Core/vtkCategoryLegend.cxx @@ -55,9 +55,9 @@ vtkCategoryLegend::~vtkCategoryLegend() bool vtkCategoryLegend::Paint(vtkContext2D* painter) { if (!this->Visible || this->ScalarsToColors == NULL || this->Values == NULL) - { + { return true; - } + } // Draw a box around the legend. painter->ApplyPen(this->Pen.GetPointer()); @@ -70,7 +70,7 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter) vtkVector2f stringBounds[2]; float titleHeight = 0.0; if (this->Title != "") - { + { painter->ApplyTextProp(this->TitleProperties.GetPointer()); painter->ComputeStringBounds(this->Title, stringBounds->GetData()); titleHeight = stringBounds[1].GetY() + this->Padding; @@ -78,7 +78,7 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter) float x = this->Rect.GetX() + this->Rect.GetWidth() / 2.0; float y = this->Rect.GetY() + this->Rect.GetHeight() - this->Padding; painter->DrawString(x, y, this->Title); - } + } painter->ApplyTextProp(this->LabelProperties.GetPointer()); @@ -98,18 +98,18 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter) // draw all of the marks & labels for (vtkIdType l = 0; l < this->Values->GetNumberOfTuples(); ++l) - { + { vtkStdString currentString = this->Values->GetValue(l).ToString(); if (currentString == "") - { + { continue; - } + } if (this->ScalarsToColors->GetAnnotatedValueIndex( this->Values->GetValue(l)) == -1) - { + { continue; - } + } // paint the color mark for this category double color[4]; @@ -122,10 +122,10 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter) // Move y position down another row y -= stringHeight + this->Padding; - } + } if (this->HasOutliers) - { + { // paint the outlier color mark double color[4]; this->ScalarsToColors->GetAnnotationColor( @@ -135,7 +135,7 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter) // draw the outlier label painter->DrawString(labelX, y, this->OutlierLabel); - } + } return true; } @@ -159,9 +159,9 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter) this->RectTime > this->PlotTime && this->RectTime > this->ScalarsToColors->GetMTime() && this->RectTime > this->Values->GetMTime()) - { + { return this->Rect; - } + } painter->ApplyTextProp(this->LabelProperties.GetPointer()); @@ -173,15 +173,15 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter) // appearance when we zoom in or out on the legend. this->Padding = static_cast(height / 4.0); if (this->Padding < 1) - { + { this->Padding = 1; - } + } // Calculate size of title (if any) float titleHeight = 0.0f; float titleWidth = 0.0f; if (this->Title != "") - { + { painter->ApplyTextProp(this->TitleProperties.GetPointer()); painter->ComputeStringBounds(this->Title, stringBounds->GetData()); @@ -189,7 +189,7 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter) titleHeight = stringBounds[1].GetY() + this->Padding; painter->ApplyTextProp(this->LabelProperties.GetPointer()); - } + } // Calculate the widest legend label float maxWidth = 0.0; @@ -198,49 +198,49 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter) this->HasOutliers = false; for (vtkIdType l = 0; l < this->Values->GetNumberOfTuples(); ++l) - { + { if (this->Values->GetValue(l).ToString() == "") - { + { ++numSkippedValues; continue; - } + } if (this->ScalarsToColors->GetAnnotatedValueIndex( this->Values->GetValue(l)) == -1) - { + { ++numSkippedValues; this->HasOutliers = true; continue; - } + } painter->ComputeStringBounds(this->Values->GetValue(l).ToString(), stringBounds->GetData()); if (stringBounds[1].GetX() > maxWidth) - { + { maxWidth = stringBounds[1].GetX(); - } } + } // Calculate size of outlier label (if necessary) if (this->HasOutliers) - { + { painter->ComputeStringBounds(this->OutlierLabel, stringBounds->GetData()); if (stringBounds[1].GetX() > maxWidth) - { + { maxWidth = stringBounds[1].GetX(); - } } + } if (titleWidth > maxWidth) - { + { this->TitleWidthOffset = (titleWidth - maxWidth) / 2.0; maxWidth = titleWidth; - } + } int numLabels = this->Values->GetNumberOfTuples() - numSkippedValues; if (this->HasOutliers) - { + { ++numLabels; - } + } // 3 paddings: one on the left, one on the right, and one between the // color mark and its label. @@ -254,21 +254,21 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter) // Compute bottom left point based on current alignment. if (this->HorizontalAlignment == vtkChartLegend::CENTER) - { + { x -= w / 2.0; - } + } else if (this->HorizontalAlignment == vtkChartLegend::RIGHT) - { + { x -= w; - } + } if (this->VerticalAlignment == vtkChartLegend::CENTER) - { + { y -= h / 2.0; - } + } else if (this->VerticalAlignment == vtkChartLegend::TOP) - { + { y -= h; - } + } this->Rect = vtkRectf(x, y, w, h); this->RectTime.Modified(); diff --git a/Charts/Core/vtkChart.cxx b/Charts/Core/vtkChart.cxx index b8c1cb8c245..e209cc045dc 100644 --- a/Charts/Core/vtkChart.cxx +++ b/Charts/Core/vtkChart.cxx @@ -73,17 +73,17 @@ vtkChart::vtkChart() vtkChart::~vtkChart() { for(int i=0; i < 4; i++) - { + { if(this->GetAxis(i)) - { + { this->GetAxis(i)->RemoveObservers(vtkChart::UpdateRange); - } } + } this->TitleProperties->Delete(); if (this->AnnotationLink) - { + { this->AnnotationLink->Delete(); - } + } } //----------------------------------------------------------------------------- @@ -108,16 +108,16 @@ bool vtkChart::RemovePlot(vtkIdType) bool vtkChart::RemovePlotInstance(vtkPlot* plot) { if (plot) - { + { vtkIdType numberOfPlots = this->GetNumberOfPlots(); for (vtkIdType i = 0; i < numberOfPlots; ++i) - { + { if (this->GetPlot(i) == plot) - { + { return this->RemovePlot(i); - } } } + } return false; } @@ -160,9 +160,9 @@ void vtkChart::RecalculateBounds() void vtkChart::SetSelectionMethod(int method) { if (method == this->SelectionMethod) - { + { return; - } + } this->SelectionMethod = method; this->Modified(); } @@ -177,10 +177,10 @@ int vtkChart::GetSelectionMethod() void vtkChart::SetShowLegend(bool visible) { if (this->ShowLegend != visible) - { + { this->ShowLegend = visible; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -198,10 +198,10 @@ vtkChartLegend * vtkChart::GetLegend() void vtkChart::SetTitle(const vtkStdString &title) { if (this->Title != title) - { + { this->Title = title; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -215,10 +215,10 @@ bool vtkChart::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform) { if (!x || !y || !transform) - { + { vtkWarningMacro("Called with null arguments."); return false; - } + } vtkVector2d origin(x->GetMinimum(), y->GetMinimum()); vtkVector2d scale(x->GetMaximum() - x->GetMinimum(), @@ -227,19 +227,19 @@ bool vtkChart::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkVector2d factor(1.0, 1.0); for (int i = 0; i < 2; ++i) - { + { if (fabs(log10(origin[i] / scale[i])) > 2) - { + { shift[i] = floor(log10(origin[i] / scale[i]) / 3.0) * 3.0; shift[i] = -origin[i]; - } + } if (fabs(log10(scale[i])) > 10) - { + { // We need to scale the transform to show all data, do this in blocks. factor[i] = pow(10.0, floor(log10(scale[i]) / 10.0) * -10.0); scale[i] = scale[i] * factor[i]; - } } + } x->SetScalingFactor(factor[0]); x->SetShift(shift[0]); y->SetScalingFactor(factor[1]); @@ -249,18 +249,18 @@ bool vtkChart::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, float *min = x->GetPoint1(); float *max = x->GetPoint2(); if (fabs(max[0] - min[0]) == 0.0) - { + { return false; - } + } float xScale = scale[0] / (max[0] - min[0]); // Now the y axis min = y->GetPoint1(); max = y->GetPoint2(); if (fabs(max[1] - min[1]) == 0.0) - { + { return false; - } + } float yScale = scale[1] / (max[1] - min[1]); transform->Identity(); @@ -277,10 +277,10 @@ bool vtkChart::CalculateUnscaledPlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform) { if (!x || !y || !transform) - { + { vtkWarningMacro("Called with null arguments."); return false; - } + } vtkVector2d scale(x->GetMaximum() - x->GetMinimum(), y->GetMaximum() - y->GetMinimum()); @@ -289,18 +289,18 @@ bool vtkChart::CalculateUnscaledPlotTransform(vtkAxis *x, vtkAxis *y, float *min = x->GetPoint1(); float *max = x->GetPoint2(); if (fabs(max[0] - min[0]) == 0.0) - { + { return false; - } + } double xScale = scale[0] / (max[0] - min[0]); // Now the y axis min = y->GetPoint1(); max = y->GetPoint2(); if (fabs(max[1] - min[1]) == 0.0) - { + { return false; - } + } double yScale = scale[1] / (max[1] - min[1]); transform->Identity(); @@ -367,18 +367,18 @@ vtkRectf vtkChart::GetSize() void vtkChart::SetActionToButton(int action, int button) { if (action < -1 || action >= MouseActions::MaxAction) - { + { vtkErrorMacro("Error, invalid action value supplied: " << action) return; - } + } this->Actions[action] = button; for (int i = 0; i < MouseActions::MaxAction; ++i) - { + { if (this->Actions[i] == button && i != action) - { + { this->Actions[i] = -1; - } } + } } int vtkChart::GetActionToButton(int action) @@ -389,10 +389,10 @@ int vtkChart::GetActionToButton(int action) void vtkChart::SetClickActionToButton(int action, int button) { if (action < vtkChart::SELECT || action > vtkChart::NOTIFY) - { + { vtkErrorMacro("Error, invalid action value supplied: " << action) return; - } + } this->Actions[action - 2] = button; } @@ -405,14 +405,14 @@ int vtkChart::GetClickActionToButton(int action) void vtkChart::SetBackgroundBrush(vtkBrush *brush) { if(brush == NULL) - { + { // set to transparent white if brush is null this->BackgroundBrush->SetColorF(1, 1, 1, 0); - } + } else - { + { this->BackgroundBrush = brush; - } + } this->Modified(); } @@ -447,21 +447,21 @@ void vtkChart::AxisRangeForwarderCallback(vtkObject*, unsigned long, void*) { double fullAxisRange[8]; for(int i=0; i < 4; i++) - { + { this->GetAxis(i)->GetRange(&fullAxisRange[i*2]); - } + } this->InvokeEvent(vtkChart::UpdateRange, fullAxisRange); } //----------------------------------------------------------------------------- void vtkChart::SetSelectionMode(int selMode) - { +{ if (this->SelectionMode == selMode || selMode < vtkContextScene::SELECTION_NONE || selMode > vtkContextScene::SELECTION_TOGGLE) - { + { return; - } + } this->SelectionMode = selMode; this->Modified(); } diff --git a/Charts/Core/vtkChart.h b/Charts/Core/vtkChart.h index bb9b735b59d..4a5455287f8 100644 --- a/Charts/Core/vtkChart.h +++ b/Charts/Core/vtkChart.h @@ -78,7 +78,7 @@ class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem SELECT_RECTANGLE = SELECT, SELECT_POLYGON, NOTIFY - }; + }; /** * Enum of event type that are triggered by the charts @@ -446,7 +446,7 @@ class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem * Hold mouse action mappings. */ class MouseActions - { + { public: MouseActions(); enum { MaxAction = 5 }; @@ -457,16 +457,16 @@ class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem short& SelectPolygon() { return Data[4]; } short& operator[](int index) { return Data[index]; } short Data[MaxAction]; - }; + }; class MouseClickActions - { + { public: MouseClickActions(); short& Notify() { return Data[0]; } short& Select() { return Data[1]; } short& operator[](int index) { return Data[index]; } short Data[2]; - }; + }; //@} MouseActions Actions; diff --git a/Charts/Core/vtkChartBox.cxx b/Charts/Core/vtkChartBox.cxx index 8acb519095d..e9982c64c2e 100644 --- a/Charts/Core/vtkChartBox.cxx +++ b/Charts/Core/vtkChartBox.cxx @@ -48,15 +48,15 @@ class vtkChartBox::Private { public: Private() - { + { this->Plot = vtkSmartPointer::New(); this->YAxis->SetPosition(vtkAxis::LEFT); this->YAxis->SetPoint1(0, 0); this->YAxis->SetTitle("Y"); - } + } ~Private() - { - } + { + } vtkSmartPointer Plot; std::vector XPosition; vtkNew Transform; @@ -105,9 +105,9 @@ void vtkChartBox::Update() { vtkTable* table = this->Storage->Plot->GetData()->GetInput(); if (!table) - { + { return; - } + } if (table->GetMTime() < this->BuildTime && this->MTime < this->BuildTime) { @@ -121,24 +121,24 @@ void vtkChartBox::Update() double grange[2] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MIN }; // Now set up their ranges and locations for (int i = 0; i < nbCols; ++i) - { + { vtkDataArray* array = vtkArrayDownCast(table->GetColumnByName( this->VisibleColumns->GetValue(i))); if (array) - { + { double range[2]; array->GetRange(range); if (range[0] < grange[0]) - { + { grange[0] = range[0]; - } + } if (range[1] > grange[1]) - { + { grange[1] = range[1]; - } } } + } this->Storage->YAxis->SetMinimum(grange[0]); this->Storage->YAxis->SetMaximum(grange[1]); @@ -154,10 +154,10 @@ bool vtkChartBox::Paint(vtkContext2D *painter) this->GetScene()->GetViewHeight() == 0 || !this->Visible || !this->Storage->Plot->GetVisible() || this->VisibleColumns->GetNumberOfTuples() < 1) - { + { // The geometry of the chart must be valid before anything can be drawn return false; - } + } //this->UpdateGeometry(painter); this->Update(); @@ -166,20 +166,20 @@ bool vtkChartBox::Paint(vtkContext2D *painter) // Handle selections vtkIdTypeArray *idArray = 0; if (this->AnnotationLink) - { + { vtkSelection *selection = this->AnnotationLink->GetCurrentSelection(); if (selection->GetNumberOfNodes() && this->AnnotationLink->GetMTime() > this->Storage->Plot->GetMTime()) - { + { vtkSelectionNode *node = selection->GetNode(0); idArray = vtkArrayDownCast(node->GetSelectionList()); this->Storage->Plot->SetSelection(idArray); - } } + } else - { + { vtkDebugMacro("No annotation link set."); - } + } painter->PushMatrix(); painter->SetTransform(this->Storage->Transform.GetPointer()); @@ -189,16 +189,16 @@ bool vtkChartBox::Paint(vtkContext2D *painter) this->Storage->YAxis->Paint(painter); if (this->GetShowLegend()) - { + { vtkRectf rect; rect.Set(0, 2, 10, 20); this->Storage->Plot->PaintLegend(painter, rect, 0); - } + } if (this->Tooltip && this->Tooltip->GetVisible()) - { + { this->Tooltip->Paint(painter); - } + } return true; } @@ -208,45 +208,45 @@ void vtkChartBox::SetColumnVisibility(const vtkStdString& name, bool visible) { if (visible) - { + { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Already there, nothing more needs to be done return; - } } + } // Add the column to the end of the list this->VisibleColumns->InsertNextValue(name); this->Modified(); this->Update(); - } + } else - { + { // Remove the value if present for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Move all the later elements down by one, and reduce the size while (i < this->VisibleColumns->GetNumberOfTuples()-1) - { + { this->VisibleColumns->SetValue(i, this->VisibleColumns->GetValue(i+1)); ++i; - } + } this->VisibleColumns->SetNumberOfTuples( this->VisibleColumns->GetNumberOfTuples()-1); if (this->SelectedColumn >= this->VisibleColumns->GetNumberOfTuples()) - { + { this->SelectedColumn = -1; - } + } this->Modified(); this->Update(); return; - } } } + } } //----------------------------------------------------------------------------- @@ -254,14 +254,14 @@ void vtkChartBox::SetColumnVisibility(vtkIdType column, bool visible) { vtkPlot *plot = this->GetPlot(0); if (!plot || !plot->GetInput()) - { + { return; - } + } vtkTable *table = plot->GetInput(); if (table) - { + { this->SetColumnVisibility(table->GetColumnName(column), visible); - } + } } //----------------------------------------------------------------------------- @@ -271,30 +271,30 @@ void vtkChartBox::SetColumnVisibilityAll(bool visible) this->VisibleColumns->SetNumberOfTuples(0); this->SelectedColumn = -1; if (visible) - { + { vtkPlot *plot = this->GetPlot(0); if (!plot || !plot->GetInput()) - { + { return; - } + } vtkTable *table = plot->GetInput(); for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i) - { + { this->SetColumnVisibility(table->GetColumnName(i), visible); - } } + } } //----------------------------------------------------------------------------- bool vtkChartBox::GetColumnVisibility(const vtkStdString& name) { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { return true; - } } + } return false; } @@ -303,9 +303,9 @@ bool vtkChartBox::GetColumnVisibility(vtkIdType column) { vtkPlot *plot = this->GetPlot(0); if (!plot || !plot->GetInput()) - { + { return false; - } + } vtkTable *table = plot->GetInput(); return this->GetColumnVisibility(table->GetColumnName(column)); } @@ -321,18 +321,18 @@ vtkIdType vtkChartBox::GetColumnId(const vtkStdString& name) { vtkPlot *plot = this->GetPlot(0); if (!plot || !plot->GetInput()) - { + { return -1; - } + } vtkTable *table = plot->GetInput(); vtkIdType nbColumn = table->GetNumberOfColumns(); for (vtkIdType i = 0; i < nbColumn; i++) - { + { if (!strcmp(table->GetColumnName(i), name.c_str())) - { + { return i; - } } + } return -1; } @@ -377,23 +377,23 @@ void vtkChartBox::UpdateGeometry(vtkContext2D* painter) if (geometry.GetX() != this->Geometry[0] || geometry.GetY() != this->Geometry[1] || !this->GeometryValid) - { + { vtkAxis* axis = this->Storage->YAxis.GetPointer(); axis->SetPoint1(0, this->Point1[1]); axis->SetPoint2(0, this->Point2[1]); if (axis->GetBehavior() == 0) - { + { axis->AutoScale(); - } + } axis->Update(); int leftBorder = 0; if (axis->GetVisible()) - { + { vtkRectf bounds = axis->GetBoundingRect(painter); leftBorder = int(bounds.GetWidth());; - } + } axis->SetPoint1(leftBorder, this->Point1[1]); axis->SetPoint2(leftBorder, this->Point2[1]); @@ -410,24 +410,24 @@ void vtkChartBox::UpdateGeometry(vtkContext2D* painter) int x = this->Point1[0] + (xStep / 2); for (int i = 0; i < nbPlots; ++i) - { + { this->Storage->XPosition[i] = x; x += xStep; - } + } this->GeometryValid = true; // Cause the plot transform to be recalculated if necessary this->CalculatePlotTransform(); if (this->VisibleColumns->GetNumberOfValues() > 1) - { + { this->Storage->Plot->SetBoxWidth(0.5f * (this->GetXPosition(1) - this->GetXPosition(0))); - } + } this->Storage->Plot->Update(); - } + } } //----------------------------------------------------------------------------- @@ -463,11 +463,11 @@ bool vtkChartBox::Hit(const vtkContextMouseEvent &mouse) bool vtkChartBox::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == this->Actions.Pan() && this->SelectedColumn >= 0) - { + { if (this->Tooltip) - { + { this->Tooltip->SetVisible(false); - } + } // Move the plot in x float posX = mouse.GetScenePos().GetX() + this->SelectedColumnDelta; @@ -480,28 +480,28 @@ bool vtkChartBox::MouseMoveEvent(const vtkContextMouseEvent &mouse) float width = this->Storage->Plot->GetBoxWidth() * 0.5f; if (left >= 0 && (posX - width) < this->Storage->XPosition[left]) - { + { this->SwapAxes(this->SelectedColumn, this->SelectedColumn - 1); this->SelectedColumn--; - } + } else if (right < nbCols && (posX + width) > this->Storage->XPosition[right]) - { + { this->SwapAxes(this->SelectedColumn, this->SelectedColumn + 1); this->SelectedColumn++; - } + } this->Scene->SetDirty(true); this->Storage->XPosition[this->SelectedColumn] = posX; - } + } if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON) - { + { this->Scene->SetDirty(true); if (this->Tooltip) - { + { this->Tooltip->SetVisible(this->LocatePointInPlots(mouse)); - } } + } return true; } @@ -509,31 +509,31 @@ bool vtkChartBox::MouseMoveEvent(const vtkContextMouseEvent &mouse) bool vtkChartBox::MouseButtonPressEvent(const vtkContextMouseEvent& mouse) { if (mouse.GetButton() == this->Actions.Pan()) - { + { // Select a plot if we are within range if (mouse.GetScenePos()[1] > this->Point1[1] && mouse.GetScenePos()[1] < this->Point2[1]) - { + { // Iterate over the axes, see if we are within 10 pixels of an axis for (size_t i = 0; i < this->Storage->XPosition.size(); ++i) - { + { float selX = this->Storage->XPosition[i]; float width = this->Storage->Plot->GetBoxWidth() / 2.f; if (selX - width < mouse.GetScenePos()[0] && selX + width > mouse.GetScenePos()[0]) - { + { this->SelectedColumn = static_cast(i); this->SelectedColumnDelta = this->GetXPosition(this->SelectedColumn) - mouse.GetScenePos().GetX(); this->Scene->SetDirty(true); return true; - } } } + } this->SelectedColumn = -1; this->Scene->SetDirty(true); return true; - } + } return false; } @@ -543,11 +543,11 @@ bool vtkChartBox::MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) { this->SelectedColumn = -1; if (mouse.GetButton() == this->Actions.Select()) - { + { if (this->SelectedColumn >= 0) - { + { if (this->AnnotationLink) - { + { vtkSelection* selection = vtkSelection::New(); vtkSelectionNode* node = vtkSelectionNode::New(); selection->AddNode(node); @@ -558,18 +558,18 @@ bool vtkChartBox::MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) this->AnnotationLink->SetCurrentSelection(selection); selection->Delete(); node->Delete(); - } + } this->InvokeEvent(vtkCommand::SelectionChangedEvent); this->Scene->SetDirty(true); - } - return true; } + return true; + } else if (mouse.GetButton() == this->Actions.Pan()) - { + { this->GeometryValid = false; this->SelectedColumn = -1; return true; - } + } this->Scene->SetDirty(true); return true; } @@ -582,19 +582,19 @@ int vtkChartBox::LocatePointInPlot(const vtkVector2f &position, vtkIdType &) { if (plot && plot->GetVisible()) - { + { vtkPlotBox* plotBar = vtkPlotBox::SafeDownCast(plot); if (plotBar) - { + { // If the plot is a vtkPlotBar, get the segment index too return plotBar->GetNearestPoint(position, tolerance, &plotPos); - } + } else - { + { return plot->GetNearestPoint(position, tolerance, &plotPos); - } } + } return -1; } @@ -607,7 +607,7 @@ bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse, pos[0] < this->Point2[0] && pos[1] > this->Point1[1] && pos[1] < this->Point2[1]) - { + { vtkVector2f plotPos, position; vtkTransform2D* transform = this->Storage->Transform.GetPointer(); @@ -623,7 +623,7 @@ bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse, LocatePointInPlot(position, tolerance, plotPos, plot, segmentIndex); if (seriesIndex >= 0) - { + { // We found a point, set up the tooltip and return vtkRectd ss(plot->GetShiftScale()); vtkVector2d plotPosd(plotPos[0] / ss[2] - ss[0], @@ -631,7 +631,7 @@ bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse, this->SetTooltipInfo(mouse, plotPosd, seriesIndex, plot, segmentIndex); if (invokeEvent >= 0) - { + { vtkChartBoxData plotIndex; plotIndex.SeriesName = this->GetVisibleColumns()->GetValue(seriesIndex); @@ -640,10 +640,10 @@ bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse, plotIndex.Index = segmentIndex; // Invoke an event, with the client data supplied this->InvokeEvent(invokeEvent, static_cast(&plotIndex)); - } - return true; } + return true; } + } return false; } @@ -651,24 +651,24 @@ bool vtkChartBox::LocatePointInPlots(const vtkContextMouseEvent &mouse, void vtkChartBox::SetTooltip(vtkTooltipItem *tooltip) { if (tooltip == this->Tooltip) - { + { // nothing to change return; - } + } if (this->Tooltip) - { + { // remove current tooltip from scene this->RemoveItem(this->Tooltip); - } + } this->Tooltip = tooltip; if (this->Tooltip) - { + { // add new tooltip to scene this->AddItem(this->Tooltip); - } + } } //----------------------------------------------------------------------------- @@ -684,9 +684,9 @@ void vtkChartBox::SetTooltipInfo(const vtkContextMouseEvent& mouse, vtkIdType segmentIndex) { if (!this->Tooltip) - { + { return; - } + } // Have the plot generate its tooltip label vtkStdString tooltipLabel = plot->GetTooltipLabel(plotPos, seriesIndex, diff --git a/Charts/Core/vtkChartHistogram2D.cxx b/Charts/Core/vtkChartHistogram2D.cxx index 9ca3492c1f7..433dfb45c09 100644 --- a/Charts/Core/vtkChartHistogram2D.cxx +++ b/Charts/Core/vtkChartHistogram2D.cxx @@ -72,9 +72,9 @@ void vtkChartHistogram2D::SetTransferFunction(vtkScalarsToColors *function) this->Histogram->SetTransferFunction(function); vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend); if (legend) - { + { legend->SetTransferFunction(function); - } + } } //----------------------------------------------------------------------------- @@ -83,11 +83,11 @@ bool vtkChartHistogram2D::UpdateLayout(vtkContext2D *painter) this->vtkChartXY::UpdateLayout(painter); vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend); if (legend) - { + { legend->SetPosition(vtkRectf(this->Point2[0] + 5, this->Point1[1], this->Legend->GetSymbolWidth(), this->Point2[1] - this->Point1[1])); - } + } this->Legend->Update(); return true; } @@ -100,22 +100,22 @@ bool vtkChartHistogram2D::Hit(const vtkContextMouseEvent &mouse) pos[0] < this->Point2[0] + 10 && pos[1] > this->Point1[1] && pos[1] < this->Point2[1]) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- vtkPlot* vtkChartHistogram2D::GetPlot(vtkIdType index) { if (index == 0) - { + { return this->Histogram; - } + } return 0; } diff --git a/Charts/Core/vtkChartLegend.cxx b/Charts/Core/vtkChartLegend.cxx index 4c896727cc2..2d4e456e438 100644 --- a/Charts/Core/vtkChartLegend.cxx +++ b/Charts/Core/vtkChartLegend.cxx @@ -91,21 +91,21 @@ void vtkChartLegend::Update() { this->Storage->ActivePlots.clear(); for (int i = 0; i < this->Storage->Chart->GetNumberOfPlots(); ++i) - { + { if (this->Storage->Chart->GetPlot(i)->GetVisible() && this->Storage->Chart->GetPlot(i)->GetLabel().length() > 0) - { + { this->Storage->ActivePlots.push_back(this->Storage->Chart->GetPlot(i)); - } + } // If we have a plot with multiple labels, we generally only want to show // the labels/legend symbols for the first one. So truncate at the first // one we encounter. if (this->Storage->Chart->GetPlot(i)->GetLabels() && this->Storage->Chart->GetPlot(i)->GetLabels()->GetNumberOfTuples() > 1) - { + { break; - } } + } this->PlotTime.Modified(); } @@ -116,9 +116,9 @@ bool vtkChartLegend::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkChartLegend."); if (!this->Visible || this->Storage->ActivePlots.size() == 0) - { + { return true; - } + } this->GetBoundingRect(painter); @@ -143,16 +143,16 @@ bool vtkChartLegend::Paint(vtkContext2D *painter) // Draw all of the legend labels and marks for(size_t i = 0; i < this->Storage->ActivePlots.size(); ++i) - { + { if (!this->Storage->ActivePlots[i]->GetLegendVisibility()) - { + { // skip if legend is not visible. continue; - } + } vtkStringArray *labels = this->Storage->ActivePlots[i]->GetLabels(); for (vtkIdType l = 0; labels && (l < labels->GetNumberOfValues()); ++l) - { + { // This is fairly hackish, but gets the text looking reasonable... // Calculate a height for a "normal" string, then if this height is greater // that offset is used to move it down. Effectively hacking in a text @@ -168,8 +168,8 @@ bool vtkChartLegend::Paint(vtkContext2D *painter) // Paint the legend mark and increment out y value. this->Storage->ActivePlots[i]->PaintLegend(painter, rect, l); rect.SetY(rect.GetY() - height - this->Padding); - } } + } return true; } @@ -179,9 +179,9 @@ vtkRectf vtkChartLegend::GetBoundingRect(vtkContext2D *painter) { if (this->CacheBounds && this->RectTime > this->GetMTime() && this->RectTime > this->PlotTime) - { + { return this->Rect; - } + } painter->ApplyTextProp(this->LabelProperties.GetPointer()); @@ -193,35 +193,35 @@ vtkRectf vtkChartLegend::GetBoundingRect(vtkContext2D *painter) // Calculate the widest legend label - needs the context to calculate font // metrics, but these could be cached. for(size_t i = 0; i < this->Storage->ActivePlots.size(); ++i) - { + { if (!this->Storage->ActivePlots[i]->GetLegendVisibility()) - { + { // skip if legend is not visible. continue; - } + } vtkStringArray *labels = this->Storage->ActivePlots[i]->GetLabels(); for (vtkIdType l = 0; labels && (l < labels->GetNumberOfTuples()); ++l) - { + { painter->ComputeStringBounds(labels->GetValue(l), stringBounds->GetData()); if (stringBounds[1].GetX() > maxWidth) - { + { maxWidth = stringBounds[1].GetX(); - } } } + } // Figure out the size of the legend box and store locally. int numLabels = 0; for(size_t i = 0; i < this->Storage->ActivePlots.size(); ++i) - { + { if (!this->Storage->ActivePlots[i]->GetLegendVisibility()) - { + { // skip if legend is not visible. continue; - } - numLabels += this->Storage->ActivePlots[i]->GetNumberOfLabels(); } + numLabels += this->Storage->ActivePlots[i]->GetNumberOfLabels(); + } // Default point placement is bottom left. this->Rect = vtkRectf(floor(this->Storage->Point.GetX()), @@ -280,14 +280,14 @@ vtkTextProperty * vtkChartLegend::GetLabelProperties() void vtkChartLegend::SetChart(vtkChart* chart) { if (this->Storage->Chart == chart) - { + { return; - } + } else - { + { this->Storage->Chart = chart; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -300,32 +300,32 @@ vtkChart* vtkChartLegend::GetChart() bool vtkChartLegend::Hit(const vtkContextMouseEvent &mouse) { if (!this->GetVisible()) - { + { return false; - } + } if (this->DragEnabled && mouse.GetPos().GetX() > this->Rect.GetX() && mouse.GetPos().GetX() < this->Rect.GetX() + this->Rect.GetWidth() && mouse.GetPos().GetY() > this->Rect.GetY() && mouse.GetPos().GetY() < this->Rect.GetY() + this->Rect.GetHeight()) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- bool vtkChartLegend::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (this->Button == vtkContextMouseEvent::LEFT_BUTTON) - { + { vtkVector2f delta = mouse.GetPos() - mouse.GetLastPos(); this->Storage->Point = this->Storage->Point + delta; this->GetScene()->SetDirty(true); this->Modified(); - } + } return true; } @@ -333,10 +333,10 @@ bool vtkChartLegend::MouseMoveEvent(const vtkContextMouseEvent &mouse) bool vtkChartLegend::MouseButtonPressEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { this->Button = vtkContextMouseEvent::LEFT_BUTTON; return true; - } + } return false; } diff --git a/Charts/Core/vtkChartLegend.h b/Charts/Core/vtkChartLegend.h index 7ba6b759951..7942e77a4c2 100644 --- a/Charts/Core/vtkChartLegend.h +++ b/Charts/Core/vtkChartLegend.h @@ -68,7 +68,7 @@ class VTKCHARTSCORE_EXPORT vtkChartLegend : public vtkContextItem TOP, BOTTOM, CUSTOM - }; + }; /** * Set point the legend box is anchored to. diff --git a/Charts/Core/vtkChartMatrix.cxx b/Charts/Core/vtkChartMatrix.cxx index 1cda4005ff7..2d5f9ce5748 100644 --- a/Charts/Core/vtkChartMatrix.cxx +++ b/Charts/Core/vtkChartMatrix.cxx @@ -65,12 +65,12 @@ bool vtkChartMatrix::Paint(vtkContext2D *painter) if (this->LayoutIsDirty || this->GetScene()->GetSceneWidth() != this->Private->Geometry.GetX() || this->GetScene()->GetSceneHeight() != this->Private->Geometry.GetY()) - { + { // Update the chart element positions this->Private->Geometry.Set(this->GetScene()->GetSceneWidth(), this->GetScene()->GetSceneHeight()); if (this->Size.GetX() > 0 && this->Size.GetY() > 0) - { + { // Calculate the increments without the gutters/borders that must be left vtkVector2f increments; increments.SetX((this->Private->Geometry.GetX() - (this->Size.GetX() - 1) * @@ -85,30 +85,30 @@ bool vtkChartMatrix::Paint(vtkContext2D *painter) float x = this->Borders[vtkAxis::LEFT]; float y = this->Borders[vtkAxis::BOTTOM]; for (int i = 0; i < this->Size.GetX(); ++i) - { + { if (i > 0) - { + { x += increments.GetX() + this->Gutter.GetX(); - } + } for (int j = 0; j < this->Size.GetY(); ++j) - { + { if (j > 0) - { + { y += increments.GetY() + this->Gutter.GetY(); - } + } else - { + { y = this->Borders[vtkAxis::BOTTOM]; - } + } vtkVector2f resize(0., 0.); vtkVector2i key(i, j); if (this->SpecificResize.find(key) != this->SpecificResize.end()) - { + { resize = this->SpecificResize[key]; - } + } size_t index = j * this->Size.GetX() + i; if (this->Private->Charts[index]) - { + { vtkChart *chart = this->Private->Charts[index]; vtkVector2i &span = this->Private->Spans[index]; chart->SetSize(vtkRectf(x + resize.GetX(), y + resize.GetY(), @@ -116,32 +116,32 @@ bool vtkChartMatrix::Paint(vtkContext2D *painter) (span.GetX() - 1) * this->Gutter.GetX(), increments.GetY() * span.GetY() - resize.GetY() + (span.GetY() - 1) * this->Gutter.GetY())); - } } } } - this->LayoutIsDirty = false; } + this->LayoutIsDirty = false; + } return Superclass::Paint(painter); } void vtkChartMatrix::SetSize(const vtkVector2i &size) { if (this->Size.GetX() != size.GetX() || this->Size.GetY() != size.GetY()) - { + { this->Size = size; if (size.GetX() * size.GetY() < static_cast(this->Private->Charts.size())) - { + { for (int i = static_cast(this->Private->Charts.size() - 1); i >= size.GetX() * size.GetY(); --i) - { + { this->RemoveItem(this->Private->Charts[i]); - } } + } this->Private->Charts.resize(size.GetX() * size.GetY()); this->Private->Spans.resize(size.GetX() * size.GetY(), vtkVector2i(1, 1)); this->LayoutIsDirty = true; - } + } } void vtkChartMatrix::SetBorders(int left, int bottom, int right, int top) @@ -216,41 +216,41 @@ void vtkChartMatrix::Allocate() bool vtkChartMatrix::SetChart(const vtkVector2i &position, vtkChart *chart) { if (position.GetX() < this->Size.GetX() && position.GetY() < this->Size.GetY()) - { + { size_t index = position.GetY() * this->Size.GetX() + position.GetX(); if (this->Private->Charts[index]) - { + { this->RemoveItem(this->Private->Charts[index]); - } + } this->Private->Charts[index] = chart; this->AddItem(chart); chart->SetLayoutStrategy(vtkChart::AXES_TO_RECT); return true; - } + } else - { + { return false; - } + } } vtkChart* vtkChartMatrix::GetChart(const vtkVector2i &position) { if (position.GetX() < this->Size.GetX() && position.GetY() < this->Size.GetY()) - { + { size_t index = position.GetY() * this->Size.GetX() + position.GetX(); if (this->Private->Charts[index] == NULL) - { + { vtkNew chart; this->Private->Charts[index] = chart.GetPointer(); this->AddItem(chart.GetPointer()); chart->SetLayoutStrategy(vtkChart::AXES_TO_RECT); - } - return this->Private->Charts[index]; } + return this->Private->Charts[index]; + } else - { + { return NULL; - } + } } bool vtkChartMatrix::SetChartSpan(const vtkVector2i& position, @@ -258,34 +258,34 @@ bool vtkChartMatrix::SetChartSpan(const vtkVector2i& position, { if (this->Size.GetX() - position.GetX() - span.GetX() < 0 || this->Size.GetY() - position.GetY() - span.GetY() < 0) - { + { return false; - } + } else - { + { this->Private->Spans[position.GetY() * this->Size.GetX() + position.GetX()] = span; this->LayoutIsDirty = true; return true; - } + } } vtkVector2i vtkChartMatrix::GetChartSpan(const vtkVector2i& position) { size_t index = position.GetY() * this->Size.GetX() + position.GetX(); if (position.GetX() < this->Size.GetX() && position.GetY() < this->Size.GetY()) - { + { return this->Private->Spans[index]; - } + } else - { + { return vtkVector2i(0, 0); - } + } } vtkVector2i vtkChartMatrix::GetChartIndex(const vtkVector2f &position) { if (this->Size.GetX() > 0 && this->Size.GetY() > 0) - { + { // Calculate the increments without the gutters/borders that must be left. vtkVector2f increments; increments.SetX((this->Private->Geometry.GetX() - (this->Size.GetX() - 1) * @@ -300,30 +300,30 @@ vtkVector2i vtkChartMatrix::GetChartIndex(const vtkVector2f &position) float x = this->Borders[vtkAxis::LEFT]; float y = this->Borders[vtkAxis::BOTTOM]; for (int i = 0; i < this->Size.GetX(); ++i) - { + { if (i > 0) - { + { x += increments.GetX() + this->Gutter.GetX(); - } + } for (int j = 0; j < this->Size.GetY(); ++j) - { + { if (j > 0) - { + { y += increments.GetY() + this->Gutter.GetY(); - } + } else - { + { y = this->Borders[vtkAxis::BOTTOM]; - } + } vtkVector2f resize(0., 0.); vtkVector2i key(i, j); if (this->SpecificResize.find(key) != this->SpecificResize.end()) - { + { resize = this->SpecificResize[key]; - } + } size_t index = j * this->Size.GetX() + i; if (this->Private->Charts[index]) - { + { vtkVector2i &span = this->Private->Spans[index]; // Check if the supplied location is within this charts area. float x2 = x + resize.GetX(); @@ -335,10 +335,10 @@ vtkVector2i vtkChartMatrix::GetChartIndex(const vtkVector2f &position) position.GetY() < (y2 + increments.GetY() * span.GetY() - resize.GetY() + (span.GetY() - 1) * this->Gutter.GetY())) return vtkVector2i(i, j); - } } } } + } return vtkVector2i(-1, -1); } diff --git a/Charts/Core/vtkChartMatrix.h b/Charts/Core/vtkChartMatrix.h index 5da2be06e42..a5bfb50fcef 100644 --- a/Charts/Core/vtkChartMatrix.h +++ b/Charts/Core/vtkChartMatrix.h @@ -80,9 +80,9 @@ class VTKCHARTSCORE_EXPORT vtkChartMatrix : public vtkAbstractContextItem virtual void GetBorders(int borders[4]) { for(int i=0;i<4;i++) - { + { borders[i]=this->Borders[i]; - } + } } //@} diff --git a/Charts/Core/vtkChartParallelCoordinates.cxx b/Charts/Core/vtkChartParallelCoordinates.cxx index e3bf7c7103e..0dfd1bf001e 100644 --- a/Charts/Core/vtkChartParallelCoordinates.cxx +++ b/Charts/Core/vtkChartParallelCoordinates.cxx @@ -44,20 +44,20 @@ class vtkChartParallelCoordinates::Private { public: Private() - { + { this->Plot = vtkSmartPointer::New(); this->Transform = vtkSmartPointer::New(); this->CurrentAxis = -1; this->AxisResize = -1; - } + } ~Private() - { + { for (std::vector::iterator it = this->Axes.begin(); it != this->Axes.end(); ++it) - { + { (*it)->Delete(); - } } + } vtkSmartPointer Plot; vtkSmartPointer Transform; std::vector Axes; @@ -100,59 +100,59 @@ void vtkChartParallelCoordinates::Update() { vtkTable* table = this->Storage->Plot->GetData()->GetInput(); if (!table) - { + { return; - } + } if (table->GetMTime() < this->BuildTime && this->MTime < this->BuildTime && this->GetScene()->GetMTime() < this->BuildTime) - { + { return; - } + } // Now we have a table, set up the axes accordingly, clear and build. if (static_cast(this->Storage->Axes.size()) != this->VisibleColumns->GetNumberOfTuples()) - { + { for (std::vector::iterator it = this->Storage->Axes.begin(); it != this->Storage->Axes.end(); ++it) - { + { this->RemoveItem(*it); (*it)->Delete(); - } + } this->Storage->Axes.clear(); this->Storage->AxesSelections.clear(); for (int i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { vtkAxis* axis = vtkAxis::New(); axis->SetPosition(vtkAxis::PARALLEL); this->AddItem(axis); this->Storage->Axes.push_back(axis); - } + } this->Storage->AxesSelections.resize(this->Storage->Axes.size(), vtkVector2f(0, 0)); - } + } // Now set up their ranges and locations for (int i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { double range[2]; vtkDataArray* array = vtkArrayDownCast(table->GetColumnByName( this->VisibleColumns->GetValue(i))); if (array) - { + { array->GetRange(range); - } + } vtkAxis* axis = this->Storage->Axes[i]; if (axis->GetBehavior() == 0) - { + { axis->SetMinimum(range[0]); axis->SetMaximum(range[1]); - } - axis->SetTitle(this->VisibleColumns->GetValue(i)); } + axis->SetTitle(this->VisibleColumns->GetValue(i)); + } this->GeometryValid = false; this->BuildTime.Modified(); @@ -165,10 +165,10 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter) this->GetScene()->GetViewHeight() == 0 || !this->Visible || !this->Storage->Plot->GetVisible() || this->VisibleColumns->GetNumberOfTuples() < 2) - { + { // The geometry of the chart must be valid before anything can be drawn return false; - } + } this->Update(); this->UpdateGeometry(); @@ -176,21 +176,21 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter) // Handle selections vtkIdTypeArray *idArray = 0; if (this->AnnotationLink) - { + { vtkSelection *selection = this->AnnotationLink->GetCurrentSelection(); if (this->AnnotationLink->GetMTime() > this->Storage->Plot->GetMTime()) - { + { vtkSelectionNode *node = selection->GetNumberOfNodes() > 0? selection->GetNode(0) : NULL; idArray = node? vtkArrayDownCast(node->GetSelectionList()) : NULL; this->Storage->Plot->SetSelection(idArray); - } } + } else - { + { vtkDebugMacro("No annotation link set."); - } + } painter->PushMatrix(); painter->AppendTransform(this->Storage->Transform); @@ -200,25 +200,25 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter) // Now we have a table, set up the axes accordingly, clear and build. for (std::vector::iterator it = this->Storage->Axes.begin(); it != this->Storage->Axes.end(); ++it) - { + { (*it)->Paint(painter); - } + } // If there is a selected axis, draw the highlight if (this->Storage->CurrentAxis >= 0) - { + { painter->GetBrush()->SetColor(200, 200, 200, 200); vtkAxis* axis = this->Storage->Axes[this->Storage->CurrentAxis]; painter->DrawRect(axis->GetPoint1()[0]-10, this->Point1[1], 20, this->Point2[1]-this->Point1[1]); - } + } // Now draw our active selections for (size_t i = 0; i < this->Storage->AxesSelections.size(); ++i) - { + { vtkVector &range = this->Storage->AxesSelections[i]; if (range[0] != range[1]) - { + { painter->GetBrush()->SetColor(200, 20, 20, 220); float x = this->Storage->Axes[i]->GetPoint1()[0] - 5; float y = range[0]; @@ -228,8 +228,8 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter) height *= this->Storage->Transform->GetMatrix()->GetElement(1, 1); painter->DrawRect(x, y, 10, height); - } } + } return true; } @@ -239,45 +239,45 @@ void vtkChartParallelCoordinates::SetColumnVisibility(const vtkStdString& name, bool visible) { if (visible) - { + { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Already there, nothing more needs to be done return; - } } + } // Add the column to the end of the list this->VisibleColumns->InsertNextValue(name); this->Modified(); this->Update(); - } + } else - { + { // Remove the value if present for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Move all the later elements down by one, and reduce the size while (i < this->VisibleColumns->GetNumberOfTuples()-1) - { + { this->VisibleColumns->SetValue(i, this->VisibleColumns->GetValue(i+1)); ++i; - } + } this->VisibleColumns->SetNumberOfTuples( this->VisibleColumns->GetNumberOfTuples()-1); if (this->Storage->CurrentAxis >= this->VisibleColumns->GetNumberOfTuples()) - { + { this->Storage->CurrentAxis = -1; - } + } this->Modified(); this->Update(); return; - } } } + } } //----------------------------------------------------------------------------- @@ -287,25 +287,25 @@ void vtkChartParallelCoordinates::SetColumnVisibilityAll(bool visible) this->VisibleColumns->SetNumberOfTuples(0); this->Storage->CurrentAxis = -1; if (visible) - { + { vtkTable *table = this->GetPlot(0)->GetInput(); for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i) - { + { this->SetColumnVisibility(table->GetColumnName(i), visible); - } } + } } //----------------------------------------------------------------------------- bool vtkChartParallelCoordinates::GetColumnVisibility(const vtkStdString& name) { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { return true; - } } + } return false; } @@ -332,13 +332,13 @@ vtkIdType vtkChartParallelCoordinates::GetNumberOfPlots() vtkAxis* vtkChartParallelCoordinates::GetAxis(int index) { if (index < this->GetNumberOfAxes()) - { + { return this->Storage->Axes[index]; - } + } else - { + { return NULL; - } + } } //----------------------------------------------------------------------------- @@ -355,7 +355,7 @@ void vtkChartParallelCoordinates::UpdateGeometry() if (geometry.GetX() != this->Geometry[0] || geometry.GetY() != this->Geometry[1] || !this->GeometryValid) - { + { // Take up the entire window right now, this could be made configurable this->SetGeometry(geometry.GetData()); @@ -369,23 +369,23 @@ void vtkChartParallelCoordinates::UpdateGeometry() int x = this->Point1[0]; for (size_t i = 0; i < this->Storage->Axes.size(); ++i) - { + { vtkAxis* axis = this->Storage->Axes[i]; axis->SetPoint1(x, this->Point1[1]); axis->SetPoint2(x, this->Point2[1]); if (axis->GetBehavior() == 0) - { + { axis->AutoScale(); - } + } axis->Update(); x += xStep; - } + } this->GeometryValid = true; // Cause the plot transform to be recalculated if necessary this->CalculatePlotTransform(); this->Storage->Plot->Update(); - } + } } //----------------------------------------------------------------------------- @@ -395,9 +395,9 @@ void vtkChartParallelCoordinates::CalculatePlotTransform() // system, where the range is from 0.0 to 1.0 in the y axis, and in screen // coordinates along the x axis. if (!this->Storage->Axes.size()) - { + { return; - } + } vtkAxis* axis = this->Storage->Axes[0]; float *min = axis->GetPoint1(); @@ -424,13 +424,13 @@ bool vtkChartParallelCoordinates::Hit(const vtkContextMouseEvent &mouse) pos[0] < this->Point2[0] + 10 && pos[1] > this->Point1[1] && pos[1] < this->Point2[1]) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -443,10 +443,10 @@ bool vtkChartParallelCoordinates::MouseEnterEvent(const vtkContextMouseEvent &) bool vtkChartParallelCoordinates::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == this->Actions.Select()) - { + { // If an axis is selected, then lets try to narrow down a selection... if (this->Storage->CurrentAxis >= 0) - { + { vtkVector &range = this->Storage->AxesSelections[this->Storage->CurrentAxis]; @@ -456,25 +456,25 @@ bool vtkChartParallelCoordinates::MouseMoveEvent(const vtkContextMouseEvent &mou current /= this->Storage->Transform->GetMatrix()->GetElement(1, 1); if (current > 1.0f) - { + { range[1] = 1.0f; - } + } else if (current < 0.0f) - { + { range[1] = 0.0f; - } + } else - { + { range[1] = current; - } } - this->Scene->SetDirty(true); } + this->Scene->SetDirty(true); + } else if (mouse.GetButton() == this->Actions.Pan()) - { + { vtkAxis* axis = this->Storage->Axes[this->Storage->CurrentAxis]; if (this->Storage->AxisResize == 0) - { + { // Move the axis in x float deltaX = mouse.GetScenePos().GetX() - mouse.GetLastScenePos().GetX(); @@ -490,18 +490,18 @@ bool vtkChartParallelCoordinates::MouseMoveEvent(const vtkContextMouseEvent &mou this->Storage->Axes[this->Storage->CurrentAxis+1] : NULL; if (leftAxis && axis->GetPoint1()[0] < leftAxis->GetPoint1()[0]) - { + { this->SwapAxes(this->Storage->CurrentAxis,this->Storage->CurrentAxis-1); this->Storage->CurrentAxis--; - } + } else if (rightAxis && axis->GetPoint1()[0] > rightAxis->GetPoint1()[0]) - { + { this->SwapAxes(this->Storage->CurrentAxis,this->Storage->CurrentAxis+1); this->Storage->CurrentAxis++; - } } + } else if (this->Storage->AxisResize == 1) - { + { // Modify the bottom axis range... float deltaY = mouse.GetScenePos().GetY() - mouse.GetLastScenePos().GetY(); float scale = (axis->GetPoint2()[1]-axis->GetPoint1()[1]) / @@ -511,18 +511,18 @@ bool vtkChartParallelCoordinates::MouseMoveEvent(const vtkContextMouseEvent &mou vtkVector& range = this->Storage->AxesSelections[this->Storage->CurrentAxis]; if (range[0] != range[1]) - { + { range[0] = range[1] = 0.0f; this->ResetSelection(); - } + } // Now update everything that needs to be axis->Update(); axis->RecalculateTickSpacing(); this->Storage->Plot->Update(); - } + } else if (this->Storage->AxisResize == 2) - { + { // Modify the bottom axis range... float deltaY = mouse.GetScenePos().GetY() - mouse.GetLastScenePos().GetY(); float scale = (axis->GetPoint2()[1]-axis->GetPoint1()[1]) / @@ -532,17 +532,17 @@ bool vtkChartParallelCoordinates::MouseMoveEvent(const vtkContextMouseEvent &mou vtkVector& range = this->Storage->AxesSelections[this->Storage->CurrentAxis]; if (range[0] != range[1]) - { + { range[0] = range[1] = 0.0f; this->ResetSelection(); - } + } axis->Update(); axis->RecalculateTickSpacing(); this->Storage->Plot->Update(); - } - this->Scene->SetDirty(true); } + this->Scene->SetDirty(true); + } return true; } @@ -558,25 +558,25 @@ bool vtkChartParallelCoordinates::MouseButtonPressEvent( const vtkContextMouseEvent& mouse) { if (mouse.GetButton() == this->Actions.Select()) - { + { // Select an axis if we are within range if (mouse.GetScenePos()[1] > this->Point1[1] && mouse.GetScenePos()[1] < this->Point2[1]) - { + { // Iterate over the axes, see if we are within 10 pixels of an axis for (size_t i = 0; i < this->Storage->Axes.size(); ++i) - { + { vtkAxis* axis = this->Storage->Axes[i]; if (axis->GetPoint1()[0]-10 < mouse.GetScenePos()[0] && axis->GetPoint1()[0]+10 > mouse.GetScenePos()[0]) - { + { this->Storage->CurrentAxis = static_cast(i); vtkVector& range = this->Storage->AxesSelections[i]; if (range[0] != range[1]) - { + { range[0] = range[1] = 0.0f; this->ResetSelection(); - } + } // Transform into normalized coordinates float low = mouse.GetScenePos()[1]; @@ -586,49 +586,49 @@ bool vtkChartParallelCoordinates::MouseButtonPressEvent( this->Scene->SetDirty(true); return true; - } } } + } this->Storage->CurrentAxis = -1; this->Scene->SetDirty(true); return true; - } + } else if (mouse.GetButton() == this->Actions.Pan()) - { + { // Middle mouse button - move and zoom the axes // Iterate over the axes, see if we are within 10 pixels of an axis for (size_t i = 0; i < this->Storage->Axes.size(); ++i) - { + { vtkAxis* axis = this->Storage->Axes[i]; if (axis->GetPoint1()[0]-10 < mouse.GetScenePos()[0] && axis->GetPoint1()[0]+10 > mouse.GetScenePos()[0]) - { + { this->Storage->CurrentAxis = static_cast(i); if (mouse.GetScenePos().GetY() > axis->GetPoint1()[1] && mouse.GetScenePos().GetY() < axis->GetPoint1()[1] + 20) - { + { // Resize the bottom of the axis this->Storage->AxisResize = 1; - } + } else if (mouse.GetScenePos().GetY() < axis->GetPoint2()[1] && mouse.GetScenePos().GetY() > axis->GetPoint2()[1] - 20) - { + { // Resize the top of the axis this->Storage->AxisResize = 2; - } + } else - { + { // Move the axis this->Storage->AxisResize = 0; - } } } - return true; } + return true; + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -636,9 +636,9 @@ bool vtkChartParallelCoordinates::MouseButtonReleaseEvent( const vtkContextMouseEvent& mouse) { if (mouse.GetButton() == this->Actions.Select()) - { + { if (this->Storage->CurrentAxis >= 0) - { + { vtkVector &range = this->Storage->AxesSelections[this->Storage->CurrentAxis]; @@ -648,39 +648,39 @@ bool vtkChartParallelCoordinates::MouseButtonReleaseEvent( // Set the final mouse position if (final > 1.0) - { + { range[1] = 1.0; - } + } else if (final < 0.0) - { + { range[1] = 0.0; - } + } else - { + { range[1] = final; - } + } if (range[0] == range[1]) - { + { this->ResetSelection(); - } + } else - { + { // Add a new selection if (range[0] < range[1]) - { + { this->Storage->Plot->SetSelectionRange(this->Storage->CurrentAxis, range[0], range[1]); - } + } else - { + { this->Storage->Plot->SetSelectionRange(this->Storage->CurrentAxis, range[1], range[0]); - } } + } if (this->AnnotationLink) - { + { vtkSelection* selection = vtkSelection::New(); vtkSelectionNode* node = vtkSelectionNode::New(); selection->AddNode(node); @@ -691,18 +691,18 @@ bool vtkChartParallelCoordinates::MouseButtonReleaseEvent( this->AnnotationLink->SetCurrentSelection(selection); selection->Delete(); node->Delete(); - } + } this->InvokeEvent(vtkCommand::SelectionChangedEvent); this->Scene->SetDirty(true); - } - return true; } + return true; + } else if (mouse.GetButton() == this->Actions.Pan()) - { + { this->Storage->CurrentAxis = -1; this->Storage->AxisResize = -1; return true; - } + } return false; } @@ -722,23 +722,23 @@ void vtkChartParallelCoordinates::ResetSelection() // Now set the remaining selections that were kept for (size_t i = 0; i < this->Storage->AxesSelections.size(); ++i) - { + { vtkVector &range = this->Storage->AxesSelections[i]; if (range[0] != range[1]) - { + { // Process the selected range and display this if (range[0] < range[1]) - { + { this->Storage->Plot->SetSelectionRange(static_cast(i), range[0], range[1]); - } + } else - { + { this->Storage->Plot->SetSelectionRange(static_cast(i), range[1], range[0]); - } } } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkChartPie.cxx b/Charts/Core/vtkChartPie.cxx index 3eb9bea5c1d..0655a00e413 100644 --- a/Charts/Core/vtkChartPie.cxx +++ b/Charts/Core/vtkChartPie.cxx @@ -34,8 +34,8 @@ class vtkChartPiePrivate { public: vtkChartPiePrivate() - { - } + { + } vtkSmartPointer Plot; }; @@ -70,9 +70,9 @@ vtkChartPie::~vtkChartPie() void vtkChartPie::Update() { if (this->Private->Plot && this->Private->Plot->GetVisible()) - { + { this->Private->Plot->Update(); - } + } this->Legend->Update(); this->Legend->SetVisible(this->ShowLegend); @@ -87,15 +87,15 @@ bool vtkChartPie::Paint(vtkContext2D *painter) int geometry[] = { this->GetScene()->GetSceneWidth(), this->GetScene()->GetSceneHeight() }; if (geometry[0] == 0 || geometry[1] == 0 || !this->Visible) - { + { // The geometry of the chart must be valid before anything can be drawn return false; - } + } this->Update(); if ( geometry[0] != this->Geometry[0] || geometry[1] != this->Geometry[1] ) - { + { // Take up the entire window right now, this could be made configurable this->SetGeometry(geometry); @@ -110,23 +110,23 @@ bool vtkChartPie::Paint(vtkContext2D *painter) // Set the dimensions of the Plot if (this->Private->Plot) - { + { this->Private->Plot->SetDimensions(20, 20, this->Geometry[0]-40, this->Geometry[1]-40); - } } + } this->PaintChildren(painter); if (this->Title) - { + { vtkPoints2D *rect = vtkPoints2D::New(); rect->InsertNextPoint(this->Point1[0], this->Point2[1]); rect->InsertNextPoint(this->Point2[0]-this->Point1[0], 10); painter->ApplyTextProp(this->TitleProperties); painter->DrawStringRect(rect, this->Title); rect->Delete(); - } + } this->Tooltip->Paint(painter); @@ -144,10 +144,10 @@ void vtkChartPie::SetScene(vtkContextScene *scene) vtkPlot * vtkChartPie::AddPlot(int /* type */) { if (!this->Private->Plot) - { + { this->Private->Plot = vtkSmartPointer::New(); this->AddItem(this->Private->Plot); - } + } return this->Private->Plot; } @@ -155,9 +155,9 @@ vtkPlot * vtkChartPie::AddPlot(int /* type */) vtkPlot* vtkChartPie::GetPlot(vtkIdType index) { if (index == 0) - { + { return this->Private->Plot; - } + } return 0; } @@ -166,13 +166,13 @@ vtkPlot* vtkChartPie::GetPlot(vtkIdType index) vtkIdType vtkChartPie::GetNumberOfPlots() { if (this->Private->Plot) - { + { return 1; - } + } else - { + { return 0; - } + } } //----------------------------------------------------------------------------- @@ -196,13 +196,13 @@ bool vtkChartPie::Hit(const vtkContextMouseEvent &mouse) pos[0] < this->Point2[0] && pos[1] > this->Point1[1] && pos[1] < this->Point2[1]) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -215,10 +215,10 @@ bool vtkChartPie::MouseEnterEvent(const vtkContextMouseEvent &) bool vtkChartPie::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON) - { + { this->Scene->SetDirty(true); this->Tooltip->SetVisible(this->LocatePointInPlots(mouse)); - } + } return true; } @@ -250,11 +250,11 @@ bool vtkChartPie::MouseWheelEvent(const vtkContextMouseEvent &, int /*delta*/) bool vtkChartPie::LocatePointInPlots(const vtkContextMouseEvent &mouse) { if (!this->Private->Plot || !this->Private->Plot->GetVisible()) - { + { return false; - } + } else - { + { int dimensions[4]; vtkVector2f position(mouse.GetScreenPos().Cast().GetData()); vtkVector2f tolerance(5, 5); @@ -266,11 +266,11 @@ bool vtkChartPie::LocatePointInPlots(const vtkContextMouseEvent &mouse) pos[0] <= dimensions[0] + dimensions[2] && pos[1] >= dimensions[1] && pos[1] <= dimensions[1] + dimensions[3]) - { + { int labelIndex = this->Private->Plot->GetNearestPoint(position, tolerance, &plotPos); if (labelIndex >= 0) - { + { const char *label = this->Private->Plot->GetLabel(labelIndex); std::ostringstream ostr; ostr << label << ": " << plotPos.GetY(); @@ -278,9 +278,9 @@ bool vtkChartPie::LocatePointInPlots(const vtkContextMouseEvent &mouse) this->Tooltip->SetPosition(mouse.GetScreenPos()[0] + 2, mouse.GetScreenPos()[1] + 2); return true; - } } } + } return false; } @@ -289,8 +289,8 @@ void vtkChartPie::PrintSelf(ostream &os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); if (this->Private->Plot) - { + { os << indent << "Plot: " << endl; this->Private->Plot->PrintSelf(os,indent.GetNextIndent()); - } + } } diff --git a/Charts/Core/vtkChartSelectionHelper.h b/Charts/Core/vtkChartSelectionHelper.h index a325750c1be..a08f236e3df 100644 --- a/Charts/Core/vtkChartSelectionHelper.h +++ b/Charts/Core/vtkChartSelectionHelper.h @@ -55,34 +55,34 @@ static void MakeSelection(vtkAnnotationLink *link, vtkIdTypeArray *selectionIds, assert(link != NULL && selectionIds != NULL); if (plot) - { + { // We are building up plot-based selections, using multiple nodes. vtkSelection *selection = link->GetCurrentSelection(); vtkSmartPointer node; for (unsigned int i = 0; i < selection->GetNumberOfNodes(); ++i) - { + { vtkSelectionNode *tmp = selection->GetNode(i); vtkPlot *selectionPlot = vtkPlot::SafeDownCast(tmp->GetProperties()->Get(vtkSelectionNode::PROP())); if (selectionPlot == plot) - { + { node = tmp; break; - } } + } if (!node) - { + { node = vtkSmartPointer::New(); selection->AddNode(node.GetPointer()); node->SetContentType(vtkSelectionNode::INDICES); node->SetFieldType(vtkSelectionNode::POINT); node->GetProperties()->Set(vtkSelectionNode::PROP(), plot); node->GetProperties()->Set(vtkSelectionNode::SOURCE(), plot->GetInput()); - } - node->SetSelectionList(selectionIds); } + node->SetSelectionList(selectionIds); + } else - { + { // Use a simple single selection node layout, remove previous selections. vtkNew selection; vtkNew node; @@ -91,7 +91,7 @@ static void MakeSelection(vtkAnnotationLink *link, vtkIdTypeArray *selectionIds, node->SetFieldType(vtkSelectionNode::POINT); node->SetSelectionList(selectionIds); link->SetCurrentSelection(selection.GetPointer()); - } + } } //@{ @@ -113,32 +113,32 @@ static void MinusSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelecti //@} while (i < size && iOld < oldSize) - { + { if (ptrSelection[i] > ptrOldSelection[iOld]) // Skip the value. - { + { output.push_back(ptrOldSelection[iOld++]); - } + } else if (ptrSelection[i] == ptrOldSelection[iOld]) // Match - remove. - { + { ++i; ++iOld; - } + } else if (ptrSelection[i] < ptrOldSelection[iOld]) // Add the new value. - { + { ++i; - } } + } while (iOld < oldSize) - { + { output.push_back(ptrOldSelection[iOld++]); - } + } selection->SetNumberOfTuples(output.size()); ptrSelection = static_cast(selection->GetVoidPointer(0)); for (std::vector::iterator it = output.begin(); it != output.end(); ++it, ++ptrSelection) - { + { *ptrSelection = *it; - } + } } //@{ @@ -165,9 +165,9 @@ static void AddSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection ptrSelection = static_cast(selection->GetVoidPointer(0)); for (std::vector::iterator i = output.begin(); i != it; ++i, ++ptrSelection) - { + { *ptrSelection = *i; - } + } } //@} @@ -188,36 +188,36 @@ static void ToggleSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelect vtkIdType i = 0; vtkIdType iOld = 0; while (i < size && iOld < oldSize) - { + { if (ptrSelection[i] > ptrOldSelection[iOld]) // Retain the value. - { + { output.push_back(ptrOldSelection[iOld++]); - } + } else if (ptrSelection[i] == ptrOldSelection[iOld]) // Match - toggle. - { + { ++i; ++iOld; - } + } else if (ptrSelection[i] < ptrOldSelection[iOld]) // Add the new value. - { + { output.push_back(ptrSelection[i++]); - } } + } while (i < size) - { + { output.push_back(ptrSelection[i++]); - } + } while (iOld < oldSize) - { + { output.push_back(ptrOldSelection[iOld++]); - } + } selection->SetNumberOfTuples(output.size()); ptrSelection = static_cast(selection->GetVoidPointer(0)); for (std::vector::iterator it = output.begin(); it != output.end(); ++it, ++ptrSelection) - { + { *ptrSelection = *it; - } + } } //@} @@ -231,13 +231,13 @@ static void BuildSelection(vtkAnnotationLink *link, int selectionMode, vtkPlot *plot) { if (!plotSelection || !oldSelection) - { + { return; - } + } // Build a selection and set it on the annotation link if not null. switch(selectionMode) - { + { case vtkContextScene::SELECTION_ADDITION: AddSelection(plotSelection, oldSelection); break; @@ -251,12 +251,12 @@ static void BuildSelection(vtkAnnotationLink *link, int selectionMode, default: // Nothing necessary - overwrite the old selection. break; - } + } if (link) - { + { MakeSelection(link, plotSelection, plot); - } + } } //@{ @@ -269,17 +269,17 @@ static int GetMouseSelectionMode(const vtkContextMouseEvent &mouse, int selectio // Mouse modifiers override the current selection mode. if (mouse.GetModifiers() & vtkContextMouseEvent::SHIFT_MODIFIER && mouse.GetModifiers() & vtkContextMouseEvent::CONTROL_MODIFIER) - { + { return vtkContextScene::SELECTION_TOGGLE; - } + } else if (mouse.GetModifiers() & vtkContextMouseEvent::CONTROL_MODIFIER) - { + { return vtkContextScene::SELECTION_ADDITION; - } + } else if (mouse.GetModifiers() & vtkContextMouseEvent::SHIFT_MODIFIER) - { + { return vtkContextScene::SELECTION_SUBTRACTION; - } + } return selectionMode; } //@} diff --git a/Charts/Core/vtkChartXY.cxx b/Charts/Core/vtkChartXY.cxx index bb97da9b7f0..825e9d1ac7d 100644 --- a/Charts/Core/vtkChartXY.cxx +++ b/Charts/Core/vtkChartXY.cxx @@ -73,32 +73,32 @@ class vtkChartXYPrivate { public: vtkChartXYPrivate() - { + { this->Colors = vtkSmartPointer::New(); this->Clip = vtkSmartPointer::New(); this->Borders[0] = 60; this->Borders[1] = 50; this->Borders[2] = 20; this->Borders[3] = 20; - } + } vtkPlot* GetPlotByColumn(vtkIdType columnId) - { + { std::vector::iterator it = this->plots.begin(); for ( ; it != this->plots.end(); ++it) - { + { vtkPlot* plot = *it; vtkTable* table = plot->GetInput(); const int idx = 1; // column if (table && table->GetColumn(columnId) == plot->GetData()->GetInputAbstractArrayToProcess(idx, table)) - { + { return plot; - } } + } return 0; - } + } std::vector plots; // Charts can contain multiple plots of data std::vector PlotCorners; // Stored by corner... @@ -141,13 +141,13 @@ vtkChartXY::vtkChartXY() // Next is the axes for (int i = 0; i < 4; ++i) - { + { this->ChartPrivate->axes.push_back(vtkAxis::New()); // By default just show the left and bottom axes this->ChartPrivate->axes.back()->SetVisible(i < 2 ? true : false); this->AttachAxisRangeListener(this->ChartPrivate->axes.back()); this->AddItem(this->ChartPrivate->axes.back()); - } + } this->ChartPrivate->axes[vtkAxis::LEFT]->SetPosition(vtkAxis::LEFT); this->ChartPrivate->axes[vtkAxis::BOTTOM]->SetPosition(vtkAxis::BOTTOM); this->ChartPrivate->axes[vtkAxis::RIGHT]->SetPosition(vtkAxis::RIGHT); @@ -190,13 +190,13 @@ vtkChartXY::vtkChartXY() vtkChartXY::~vtkChartXY() { for (unsigned int i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { this->ChartPrivate->plots[i]->Delete(); - } + } for (size_t i = 0; i < 4; ++i) - { + { this->ChartPrivate->axes[i]->Delete(); - } + } delete this->ChartPrivate; this->ChartPrivate = 0; } @@ -207,20 +207,20 @@ void vtkChartXY::Update() // Perform any necessary updates that are not graphical // Update the plots if necessary for (size_t i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { this->ChartPrivate->plots[i]->Update(); - } + } this->Legend->Update(); // Update the selections if necessary. if (this->AnnotationLink) - { + { this->AnnotationLink->Update(); vtkSelection *selection = vtkSelection::SafeDownCast(this->AnnotationLink->GetOutputDataObject(2)); // Two major selection methods - row based or plot based. if (this->SelectionMethod == vtkChart::SELECTION_ROWS) - { + { vtkSelectionNode *node = selection->GetNumberOfNodes() > 0? selection->GetNode(0) : NULL; vtkIdTypeArray *idArray = node? @@ -228,15 +228,15 @@ void vtkChartXY::Update() std::vector::iterator it = this->ChartPrivate->plots.begin(); for ( ; it != this->ChartPrivate->plots.end(); ++it) - { + { // Use the first selection node for all plots to select the rows. (*it)->SetSelection(idArray); - } } + } else if (this->SelectionMethod == vtkChart::SELECTION_PLOTS) - { + { for (unsigned int i = 0; i < selection->GetNumberOfNodes(); ++i) - { + { vtkSelectionNode *node = selection->GetNode(i); vtkIdTypeArray *idArray = vtkArrayDownCast(node->GetSelectionList()); @@ -246,38 +246,38 @@ void vtkChartXY::Update() std::vector::iterator it = this->ChartPrivate->plots.begin(); for ( ; it != this->ChartPrivate->plots.end(); ++it) - { + { if (selectionPlot == *it) - { + { (*it)->SetSelection(idArray); - } } } } + } else if (this->SelectionMethod == vtkChart::SELECTION_COLUMNS) - { + { // Retrieve all the selected plots std::vector selectedPlots; for (unsigned int i = 0; i < selection->GetNumberOfNodes(); ++i) - { + { vtkSelectionNode *node = selection->GetNode(i); vtkIdTypeArray *selectedColumns = vtkArrayDownCast(node->GetSelectionList()); vtkIdType* ptr = reinterpret_cast(selectedColumns->GetVoidPointer(0)); for (vtkIdType j = 0; j < selectedColumns->GetNumberOfTuples(); ++j) - { + { vtkPlot* selectedPlot = this->ChartPrivate->GetPlotByColumn(ptr[j]); if (selectedPlot) - { + { selectedPlots.push_back(selectedPlot); - } } } + } // Now iterate through the plots to update selection data std::vector::iterator it = this->ChartPrivate->plots.begin(); for ( ; it != this->ChartPrivate->plots.end(); ++it) - { + { vtkPlot* plot = *it; vtkIdTypeArray* plotSelection = 0; bool ownPlotSelection = false; @@ -285,62 +285,62 @@ void vtkChartXY::Update() std::find(selectedPlots.begin(), selectedPlots.end(), plot) != selectedPlots.end(); if (isSelected) - { + { static int idx = 1; // y vtkAbstractArray* column = plot->GetData()->GetInputAbstractArrayToProcess( idx, plot->GetInput()); plotSelection = plot->GetSelection(); if (!plotSelection || plotSelection->GetNumberOfTuples() != column->GetNumberOfTuples()) - { + { plotSelection = vtkIdTypeArray::New(); ownPlotSelection = true; for (vtkIdType j = 0; j < column->GetNumberOfTuples(); ++j) - { + { plotSelection->InsertNextValue(j); - } } } + } plot->SetSelection(plotSelection); if (ownPlotSelection) - { + { plotSelection->Delete(); - } } } } + } else - { + { vtkDebugMacro("No annotation link set."); - } + } this->CalculateBarPlots(); if (this->AutoAxes) - { + { vtkTuple visibilities(false); for (int i = 0; i < static_cast(this->ChartPrivate->PlotCorners.size()); ++i) - { + { int visible = 0; for (unsigned int j = 0; j < this->ChartPrivate->PlotCorners[i]->GetNumberOfItems(); ++j) - { + { if (vtkPlot::SafeDownCast(this->ChartPrivate->PlotCorners[i] ->GetItem(j))->GetVisible()) - { + { ++visible; - } } + } if (visible) - { + { visibilities[i % 4] = true; visibilities[(i+1) % 4] = true; - } } + } for (int i = 0; i < 4; ++i) - { + { this->ChartPrivate->axes[i]->SetVisible(visibilities[i]); - } } + } } //----------------------------------------------------------------------------- @@ -349,68 +349,68 @@ bool vtkChartXY::Paint(vtkContext2D *painter) // This is where everything should be drawn, or dispatched to other methods. vtkDebugMacro(<< "Paint event called."); if (!this->Visible) - { + { // The geometry of the chart must be valid before anything can be drawn return false; - } + } vtkVector2i geometry(0, 0); bool recalculateTransform = false; if (this->LayoutStrategy == vtkChart::FILL_SCENE) - { + { geometry = vtkVector2i(this->GetScene()->GetSceneWidth(), this->GetScene()->GetSceneHeight()); if (geometry.GetX() != this->Geometry[0] || geometry.GetY() != this->Geometry[1]) - { + { recalculateTransform = true; this->LayoutChanged = true; - } - this->SetSize(vtkRectf(0.0, 0.0, geometry.GetX(), geometry.GetY())); } + this->SetSize(vtkRectf(0.0, 0.0, geometry.GetX(), geometry.GetY())); + } int visiblePlots = 0; for (size_t i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { if (this->ChartPrivate->plots[i]->GetVisible()) - { + { ++visiblePlots; - } } + } if (visiblePlots == 0 && !this->RenderEmpty) - { + { // Nothing to plot, so don't draw anything. return false; - } + } this->Update(); if (this->MTime < this->ChartPrivate->axes[0]->GetMTime()) - { + { // Cause the plot transform to be recalculated if necessary recalculateTransform = true; this->LayoutChanged = true; - } + } this->UpdateLayout(painter); // Recalculate the plot transform, min and max values if necessary if (!this->PlotTransformValid) - { + { this->RecalculatePlotBounds(); recalculateTransform = true; - } + } if (this->UpdateLayout(painter) || recalculateTransform) - { + { this->RecalculatePlotTransforms(); - } + } // Now that plot transforms, including whether to use log scaling and the // shift-scale factors, have been updated, we give the vtkPlot instances an // opportunity to update caches. for (size_t i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { this->ChartPrivate->plots[i]->UpdateCache(); - } + } // Update the clipping if necessary this->ChartPrivate->Clip->SetClip(this->Point1[0], this->Point1[1], @@ -419,30 +419,30 @@ bool vtkChartXY::Paint(vtkContext2D *painter) // draw background if(this->BackgroundBrush) - { + { painter->GetPen()->SetLineType(vtkPen::NO_PEN); painter->ApplyBrush(this->BackgroundBrush); painter->DrawRect(this->Point1[0], this->Point1[1], this->Geometry[0], this->Geometry[1]); - } + } // Use the scene to render most of the chart. this->PaintChildren(painter); // Draw the selection box if necessary if (this->DrawBox) - { + { painter->GetBrush()->SetColor(255, 255, 255, 0); painter->GetPen()->SetColor(0, 0, 0, 255); painter->GetPen()->SetWidth(1.0); painter->GetPen()->SetLineType(vtkPen::SOLID_LINE); painter->DrawRect(this->MouseBox.GetX(), this->MouseBox.GetY(), this->MouseBox.GetWidth(), this->MouseBox.GetHeight()); - } + } // Draw the selection polygon if necessary if (this->DrawSelectionPolygon) - { + { painter->GetBrush()->SetColor(255, 0, 0, 0); painter->GetPen()->SetColor(0, 255, 0, 255); painter->GetPen()->SetWidth(2.0); @@ -452,39 +452,39 @@ bool vtkChartXY::Paint(vtkContext2D *painter) // draw each line segment for(vtkIdType i = 0; i < polygon.GetNumberOfPoints() - 1; i++) - { + { const vtkVector2f &a = polygon.GetPoint(i); const vtkVector2f &b = polygon.GetPoint(i+1); painter->DrawLine(a.GetX(), a.GetY(), b.GetX(), b.GetY()); - } + } // draw a line from the end to the start if(polygon.GetNumberOfPoints() >= 3) - { + { const vtkVector2f &start = polygon.GetPoint(0); const vtkVector2f &end = polygon.GetPoint(polygon.GetNumberOfPoints() - 1); painter->DrawLine(start.GetX(), start.GetY(), end.GetX(), end.GetY()); - } } + } if (this->Title) - { + { int offset = 0; // title margin. vtkAxis* topAxis = this->ChartPrivate->axes[vtkAxis::TOP]; if (topAxis->GetVisible()) - { + { vtkRectf bounds = topAxis->GetBoundingRect(painter); offset += static_cast(bounds.GetHeight()); - } + } vtkPoints2D *rect = vtkPoints2D::New(); rect->InsertNextPoint(this->Point1[0], this->Point2[1] + offset); rect->InsertNextPoint(this->Point2[0]-this->Point1[0], 10); painter->ApplyTextProp(this->TitleProperties); painter->DrawStringRect(rect, this->Title); rect->Delete(); - } + } return true; } @@ -496,44 +496,44 @@ void vtkChartXY::CalculateBarPlots() size_t n = this->ChartPrivate->plots.size(); std::vector bars; for (size_t i = 0; i < n; ++i) - { + { vtkPlotBar* bar = vtkPlotBar::SafeDownCast(this->ChartPrivate->plots[i]); if (bar && bar->GetVisible()) - { + { bars.push_back(bar); - } } + } if (bars.size()) - { + { // We have some bar plots - work out offsets etc. float barWidth = 0.1; vtkPlotBar* bar = bars[0]; if (!bar->GetUseIndexForXSeries()) - { + { vtkTable *table = bar->GetData()->GetInput(); if (table) - { + { vtkDataArray* x = bar->GetData()->GetInputArrayToProcess(0, table); if (x && x->GetNumberOfTuples() > 1) - { + { double x0 = x->GetTuple1(0); double x1 = x->GetTuple1(1); float width = static_cast(fabs(x1 - x0) * this->BarWidthFraction); barWidth = width / bars.size(); - } } } + } else - { + { barWidth = 1.0f / bars.size() * this->BarWidthFraction; - } + } // Now set the offsets and widths on each bar // The offsetIndex deals with the fact that half the bars // must shift to the left of the point and half to the right int offsetIndex = static_cast(bars.size() - 1); for (size_t i = 0; i < bars.size(); ++i) - { + { bars[i]->SetWidth(barWidth); bars[i]->SetOffset(offsetIndex * (barWidth / 2)); // Increment by two since we need to shift by half widths @@ -543,28 +543,28 @@ void vtkChartXY::CalculateBarPlots() // to the right. offsetIndex -= 2; //bars[i]->SetOffset(float(bars.size()-i-1)*(barWidth/2)); - } } + } } //----------------------------------------------------------------------------- void vtkChartXY::RecalculatePlotTransforms() { for (int i = 0; i < int(this->ChartPrivate->PlotCorners.size()); ++i) - { + { if (this->ChartPrivate->PlotCorners[i]->GetNumberOfItems()) - { + { vtkAxis *xAxis = 0; vtkAxis *yAxis = 0; // Get the appropriate axes, and recalculate the transform. switch (i) - { + { case 0: - { + { xAxis = this->ChartPrivate->axes[vtkAxis::BOTTOM]; yAxis = this->ChartPrivate->axes[vtkAxis::LEFT]; break; - } + } case 1: xAxis = this->ChartPrivate->axes[vtkAxis::BOTTOM]; yAxis = this->ChartPrivate->axes[vtkAxis::RIGHT]; @@ -580,7 +580,7 @@ void vtkChartXY::RecalculatePlotTransforms() default: vtkWarningMacro( "Error: default case in recalculate plot transforms."); - } + } this->CalculatePlotTransform( xAxis, yAxis, this->ChartPrivate->PlotCorners[i]->GetTransform()); // Now we need to set the scale factor on the plots to ensure they rescale @@ -589,16 +589,16 @@ void vtkChartXY::RecalculatePlotTransforms() xAxis->GetScalingFactor(), yAxis->GetScalingFactor()); for (unsigned int j = 0; j < this->ChartPrivate->PlotCorners[i]->GetNumberOfItems(); ++j) - { + { vtkPlot *plot = vtkPlot::SafeDownCast(this->ChartPrivate->PlotCorners[i]->GetItem(j)); if (plot) - { + { plot->SetShiftScale(shiftScale); - } } } } + } this->PlotTransformValid = true; } @@ -609,73 +609,73 @@ int vtkChartXY::GetPlotCorner(vtkPlot *plot) vtkAxis *y = plot->GetYAxis(); if (x == this->ChartPrivate->axes[vtkAxis::BOTTOM] && y == this->ChartPrivate->axes[vtkAxis::LEFT]) - { + { return 0; - } + } else if (x == this->ChartPrivate->axes[vtkAxis::BOTTOM] && y == this->ChartPrivate->axes[vtkAxis::RIGHT]) - { + { return 1; - } + } else if (x == this->ChartPrivate->axes[vtkAxis::TOP] && y == this->ChartPrivate->axes[vtkAxis::RIGHT]) - { + { return 2; - } + } else if (x == this->ChartPrivate->axes[vtkAxis::TOP] && y == this->ChartPrivate->axes[vtkAxis::LEFT]) - { + { return 3; - } + } else - { + { // Should never happen. return 4; - } + } } //----------------------------------------------------------------------------- void vtkChartXY::SetPlotCorner(vtkPlot *plot, int corner) { if (corner < 0 || corner > 3) - { + { vtkWarningMacro("Invalid corner specified, should be between 0 and 3: " << corner); return; - } + } if (this->GetPlotCorner(plot) == corner) - { + { return; - } + } this->RemovePlotFromCorners(plot); // Grow the plot corners if necessary while (static_cast(this->ChartPrivate->PlotCorners.size() - 1) < corner) - { + { vtkNew transform; this->ChartPrivate->PlotCorners.push_back(transform.GetPointer()); this->ChartPrivate->Clip->AddItem(transform.GetPointer()); // Clip maintains ownership. - } + } this->ChartPrivate->PlotCorners[corner]->AddItem(plot); if (corner == 0) - { + { plot->SetXAxis(this->ChartPrivate->axes[vtkAxis::BOTTOM]); plot->SetYAxis(this->ChartPrivate->axes[vtkAxis::LEFT]); - } + } else if (corner == 1) - { + { plot->SetXAxis(this->ChartPrivate->axes[vtkAxis::BOTTOM]); plot->SetYAxis(this->ChartPrivate->axes[vtkAxis::RIGHT]); - } + } else if (corner == 2) - { + { plot->SetXAxis(this->ChartPrivate->axes[vtkAxis::TOP]); plot->SetYAxis(this->ChartPrivate->axes[vtkAxis::RIGHT]); - } + } else if (corner == 3) - { + { plot->SetXAxis(this->ChartPrivate->axes[vtkAxis::TOP]); plot->SetYAxis(this->ChartPrivate->axes[vtkAxis::LEFT]); - } + } this->PlotTransformValid = false; } @@ -694,109 +694,109 @@ void vtkChartXY::RecalculatePlotBounds() double bounds[4] = { 0.0, 0.0, 0.0, 0.0 }; for (it = this->ChartPrivate->plots.begin(); it != this->ChartPrivate->plots.end(); ++it) - { + { if ((*it)->GetVisible() == false) - { + { continue; - } + } (*it)->GetBounds(bounds); if (bounds[1] - bounds[0] < 0.0) - { + { // skip uninitialized bounds. continue; - } + } int corner = this->GetPlotCorner(*it); // Initialize the appropriate ranges, or push out the ranges if ((corner == 0 || corner == 3)) // left - { + { if (!initialized[0]) - { + { y1[0] = bounds[2]; y1[1] = bounds[3]; initialized[0] = true; - } + } else - { + { if (y1[0] > bounds[2]) // min - { + { y1[0] = bounds[2]; - } + } if (y1[1] < bounds[3]) // max - { + { y1[1] = bounds[3]; - } } } + } if ((corner == 0 || corner == 1)) // bottom - { + { if (!initialized[1]) - { + { x1[0] = bounds[0]; x1[1] = bounds[1]; initialized[1] = true; - } + } else - { + { if (x1[0] > bounds[0]) // min - { + { x1[0] = bounds[0]; - } + } if (x1[1] < bounds[1]) // max - { + { x1[1] = bounds[1]; - } } } + } if ((corner == 1 || corner == 2)) // right - { + { if (!initialized[2]) - { + { y2[0] = bounds[2]; y2[1] = bounds[3]; initialized[2] = true; - } + } else - { + { if (y2[0] > bounds[2]) // min - { + { y2[0] = bounds[2]; - } + } if (y2[1] < bounds[3]) // max - { + { y2[1] = bounds[3]; - } } } + } if ((corner == 2 || corner == 3)) // top - { + { if (!initialized[3]) - { + { x2[0] = bounds[0]; x2[1] = bounds[1]; initialized[3] = true; - } + } else - { + { if (x2[0] > bounds[0]) // min - { + { x2[0] = bounds[0]; - } + } if (x2[1] < bounds[1]) // max - { + { x2[1] = bounds[1]; - } } } } + } // Now set the newly calculated bounds on the axes for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = this->ChartPrivate->axes[i]; double *range = 0; switch (i) - { + { case 0: range = y1; break; @@ -811,32 +811,32 @@ void vtkChartXY::RecalculatePlotBounds() break; default: return; - } + } if (this->AdjustLowerBoundForLogPlot && axis->GetLogScale() && range[0] <= 0.) - { + { if (range[1] <= 0.) - { + { // All of the data is negative, so we arbitrarily set the axis range to // be positive and show no data range[1] = 1.; - } + } // The minimum value is set to either 4 decades below the max or to 1, // regardless of the true minimum value (which is less than 0) range[0] = (range[1] < 1.e4 ? range[1] / 1.e4 : 1.); - } + } if (this->ForceAxesToBounds) - { + { axis->SetMinimumLimit(range[0]); axis->SetMaximumLimit(range[1]); - } + } if (axis->GetBehavior() == vtkAxis::AUTO && initialized[i]) - { + { axis->SetRange(range[0], range[1]); axis->AutoScale(); - } } + } this->Modified(); } @@ -854,58 +854,58 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) // Axes if (this->LayoutStrategy == vtkChart::FILL_SCENE || this->LayoutStrategy == vtkChart::FILL_RECT) - { + { for (int i = 0; i < 4; ++i) - { + { int border = 0; vtkAxis* axis = this->ChartPrivate->axes[i]; axis->Update(); if (axis->GetVisible()) - { + { vtkRectf bounds = axis->GetBoundingRect(painter); if (i == vtkAxis::TOP || i == vtkAxis::BOTTOM) - {// Horizontal axes + {// Horizontal axes border = int(bounds.GetHeight()); - } + } else - {// Vertical axes + {// Vertical axes border = int(bounds.GetWidth()); - } } + } border += this->GetLegendBorder(painter, i); if (i == vtkAxis::TOP && this->Title) - { + { painter->ApplyTextProp(this->TitleProperties); float bounds[4]; painter->ComputeStringBounds(this->Title, bounds); if (bounds[3] > 0) - { + { border += (5 * tileScale.GetY()) /* title margin */ + bounds[3]; // add the title text height to the border. - } } + } if (i == vtkAxis::TOP || i == vtkAxis::BOTTOM) - { + { border = std::max(border, hiddenAxisBorder.GetY()); - } + } else - { + { border = std::max(border, hiddenAxisBorder.GetX()); - } + } if (this->ChartPrivate->Borders[i] != border) - { + { this->ChartPrivate->Borders[i] = border; changed = true; - } } } + } if (this->LayoutChanged || changed) - { + { if (this->DrawAxesAtOrigin) - { + { this->SetBorders(hiddenAxisBorder.GetX(), hiddenAxisBorder.GetY(), this->ChartPrivate->Borders[2], @@ -917,21 +917,21 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) transform->TransformPoints(origin.GetData(), origin.GetData(), 1); // Need to clamp the axes in the plot area. if (int(origin[0]) < this->Point1[0]) - { + { origin[0] = this->Point1[0]; - } + } if (int(origin[0]) > this->Point2[0]) - { + { origin[0] = this->Point2[0]; - } + } if (int(origin[1]) < this->Point1[1]) - { + { origin[1] = this->Point1[1]; - } + } if (int(origin[1]) > this->Point2[1]) - { + { origin[1] = this->Point2[1]; - } + } this->ChartPrivate->axes[vtkAxis::BOTTOM] ->SetPoint1(this->Point1[0], origin[1]); @@ -941,24 +941,24 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) ->SetPoint1(origin[0], this->Point1[1]); this->ChartPrivate->axes[vtkAxis::LEFT] ->SetPoint2(origin[0], this->Point2[1]); - } + } else - { + { if (this->LayoutStrategy == vtkChart::AXES_TO_RECT) - { + { this->SetBorders(0, 0, 0, 0); this->ChartPrivate->axes[0]->GetBoundingRect(painter); this->ChartPrivate->axes[1]->GetBoundingRect(painter); this->ChartPrivate->axes[2]->GetBoundingRect(painter); this->ChartPrivate->axes[3]->GetBoundingRect(painter); - } + } else - { + { this->SetBorders(this->ChartPrivate->Borders[0], this->ChartPrivate->Borders[1], this->ChartPrivate->Borders[2], this->ChartPrivate->Borders[3]); - } + } // This is where we set the axes up too // Y axis (left) this->ChartPrivate->axes[0]->SetPoint1(this->Point1[0], this->Point1[1]); @@ -966,7 +966,7 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) // X axis (bottom) this->ChartPrivate->axes[1]->SetPoint1(this->Point1[0], this->Point1[1]); this->ChartPrivate->axes[1]->SetPoint2(this->Point2[0], this->Point1[1]); - } + } // Y axis (right) this->ChartPrivate->axes[2]->SetPoint1(this->Point2[0], this->Point1[1]); this->ChartPrivate->axes[2]->SetPoint2(this->Point2[0], this->Point2[1]); @@ -975,10 +975,10 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) this->ChartPrivate->axes[3]->SetPoint2(this->Point2[0], this->Point2[1]); for (int i = 0; i < 4; ++i) - { + { this->ChartPrivate->axes[i]->Update(); - } } + } this->SetLegendPosition(this->Legend->GetBoundingRect(painter)); return changed; @@ -988,9 +988,9 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter) int vtkChartXY::GetLegendBorder(vtkContext2D* painter, int axisPosition) { if (!this->Legend->GetVisible() || this->Legend->GetInline()) - { + { return 0; - } + } vtkVector2i tileScale = this->Scene->GetLogicalTileScale(); @@ -1006,34 +1006,34 @@ int vtkChartXY::GetLegendBorder(vtkContext2D* painter, int axisPosition) // Figure out the correct place and alignment based on the legend layout. if (axisPosition == vtkAxis::LEFT && legendAlignment.GetX() == vtkChartLegend::LEFT) - { + { return legendSize.GetX() + padding * tileScale.GetX(); - } + } else if (axisPosition == vtkAxis::RIGHT && legendAlignment.GetX() == vtkChartLegend::RIGHT) - { + { return legendSize.GetX() + padding * tileScale.GetX(); - } + } else if ((axisPosition == vtkAxis::TOP || axisPosition == vtkAxis::BOTTOM) && (legendAlignment.GetX() == vtkChartLegend::LEFT || legendAlignment.GetX() == vtkChartLegend::RIGHT)) - { + { return 0; - } + } else if (axisPosition == vtkAxis::TOP && legendAlignment.GetY() == vtkChartLegend::TOP) - { + { return legendSize.GetY() + padding * tileScale.GetY(); - } + } else if (axisPosition == vtkAxis::BOTTOM && legendAlignment.GetY() == vtkChartLegend::BOTTOM) - { + { return legendSize.GetY() + padding * tileScale.GetY(); - } + } else - { + { return 0; - } + } } //----------------------------------------------------------------------------- @@ -1047,14 +1047,14 @@ void vtkChartXY::SetLegendPosition(const vtkRectf& rect) if (legendAlignment[0] == vtkChartLegend::CUSTOM || legendAlignment[1] == vtkChartLegend::CUSTOM) - { + { return; - } + } if (this->Legend->GetInline()) - { + { switch (this->Legend->GetHorizontalAlignment()) - { + { case vtkChartLegend::LEFT: pos.SetX(this->Point1[0]); break; @@ -1065,9 +1065,9 @@ void vtkChartXY::SetLegendPosition(const vtkRectf& rect) case vtkChartLegend::RIGHT: default: pos.SetX(this->Point2[0] - rect.GetWidth()); - } + } switch (this->Legend->GetVerticalAlignment()) - { + { case vtkChartLegend::TOP: pos.SetY(this->Point2[1] - rect.GetHeight()); break; @@ -1078,55 +1078,55 @@ void vtkChartXY::SetLegendPosition(const vtkRectf& rect) case vtkChartLegend::BOTTOM: default: pos.SetY(this->Point1[1]); - } } + } else - { + { // Non-inline legends. if (legendAlignment.GetX() == vtkChartLegend::LEFT) - { + { pos.SetX(this->Point1[0] - this->ChartPrivate->Borders[vtkAxis::LEFT] + padding); - } + } else if (legendAlignment.GetX() == vtkChartLegend::RIGHT) - { + { pos.SetX(this->Point2[0] + this->ChartPrivate->Borders[vtkAxis::RIGHT] - rect.GetWidth() - padding); - } + } else if (legendAlignment.GetX() == vtkChartLegend::CENTER) - { + { pos.SetX(((this->Point2[0] - this->Point1[0]) / 2.0) - (rect.GetWidth() / 2.0) + this->Point1[0]); // Check for the special case where the legend is on the top or bottom if (legendAlignment.GetY() == vtkChartLegend::TOP) - { + { pos.SetY(this->Point2[1] + this->ChartPrivate->Borders[vtkAxis::TOP] - rect.GetHeight() - padding); - } + } else if (legendAlignment.GetY() == vtkChartLegend::BOTTOM) - { + { pos.SetY(this->Point1[1] - this->ChartPrivate->Borders[vtkAxis::BOTTOM] + padding); - } } + } // Vertical alignment if (legendAlignment.GetX() != vtkChartLegend::CENTER) - { + { if (legendAlignment.GetY() == vtkChartLegend::TOP) - { + { pos.SetY(this->Point2[1] - rect.GetHeight()); - } + } else if (legendAlignment.GetY() == vtkChartLegend::BOTTOM) - { + { pos.SetY(this->Point1[1]); - } } + } if (legendAlignment.GetY() == vtkChartLegend::CENTER) - { + { pos.SetY(((this->Point2[1] - this->Point1[1]) / 2.0) - (rect.GetHeight() / 2.0) + this->Point1[1]); - } } + } this->Legend->SetPoint(pos); } @@ -1142,69 +1142,69 @@ vtkPlot * vtkChartXY::AddPlot(int type) vtkColor3ub color = this->ChartPrivate->Colors->GetColorRepeating( static_cast(this->ChartPrivate->plots.size())); switch (type) - { + { case LINE: - { + { vtkPlotLine *line = vtkPlotLine::New(); line->GetPen()->SetColor(color.GetData()); plot = line; break; - } + } case POINTS: - { + { vtkPlotPoints *points = vtkPlotPoints::New(); points->GetPen()->SetColor(color.GetData()); plot = points; break; - } + } case BAR: - { + { vtkPlotBar *bar = vtkPlotBar::New(); bar->GetBrush()->SetColor(color.GetData()); plot = bar; break; - } + } case FUNCTIONALBAG: - { + { vtkPlotFunctionalBag *bag = vtkPlotFunctionalBag::New(); bag->GetPen()->SetColor(color.GetData()); bag->GetBrush()->SetColor(color.GetData()); plot = bag; break; - } + } case STACKED: - { + { vtkPlotStacked *stacked = vtkPlotStacked::New(); stacked->SetParent(this); stacked->GetBrush()->SetColor(color.GetData()); plot = stacked; break; - } + } case BAG: - { + { vtkPlotBag *bag = vtkPlotBag::New(); bag->SetParent(this); bag->GetBrush()->SetColor(color.GetData()); plot = bag; break; - } + } case AREA: - { + { vtkPlotArea* area = vtkPlotArea::New(); area->SetParent(this); area->GetBrush()->SetColor(color.GetData()); plot = area; break; - } + } default: plot = NULL; - } + } if (plot) - { + { this->AddPlot(plot); plot->Delete(); - } + } return plot; } @@ -1212,9 +1212,9 @@ vtkPlot * vtkChartXY::AddPlot(int type) vtkIdType vtkChartXY::AddPlot(vtkPlot * plot) { if (plot == NULL) - { + { return -1; - } + } plot->Register(this); this->ChartPrivate->plots.push_back(plot); vtkIdType plotIndex = this->ChartPrivate->plots.size() - 1; @@ -1223,9 +1223,9 @@ vtkIdType vtkChartXY::AddPlot(vtkPlot * plot) this->PlotTransformValid = false; // Mark the scene as dirty if (this->Scene) - { + { this->Scene->SetDirty(true); - } + } return plotIndex; } @@ -1233,7 +1233,7 @@ vtkIdType vtkChartXY::AddPlot(vtkPlot * plot) bool vtkChartXY::RemovePlot(vtkIdType index) { if (index < static_cast(this->ChartPrivate->plots.size())) - { + { this->RemovePlotFromCorners(this->ChartPrivate->plots[index]); this->ChartPrivate->plots[index]->Delete(); this->ChartPrivate->plots.erase(this->ChartPrivate->plots.begin()+index); @@ -1241,57 +1241,57 @@ bool vtkChartXY::RemovePlot(vtkIdType index) // Ensure that the bounds are recalculated this->PlotTransformValid = false; if (this->Scene) - { + { // Mark the scene as dirty this->Scene->SetDirty(true); - } - return true; } + return true; + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- void vtkChartXY::ClearPlots() { for (unsigned int i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { this->ChartPrivate->plots[i]->Delete(); - } + } this->ChartPrivate->plots.clear(); // Clear the corners too for (int i = 0; i < int(this->ChartPrivate->PlotCorners.size()); ++i) - { + { this->ChartPrivate->PlotCorners[i]->ClearItems(); if (i > 0) - { + { this->ChartPrivate->Clip->RemoveItem(this->ChartPrivate->PlotCorners[i]); - } } + } this->ChartPrivate->PlotCorners.resize(1); // Ensure that the bounds are recalculated this->PlotTransformValid = false; if (this->Scene) - { + { // Mark the scene as dirty this->Scene->SetDirty(true); - } + } } //----------------------------------------------------------------------------- vtkPlot* vtkChartXY::GetPlot(vtkIdType index) { if (static_cast(this->ChartPrivate->plots.size()) > index) - { + { return this->ChartPrivate->plots[index]; - } + } else - { + { return NULL; - } + } } //----------------------------------------------------------------------------- @@ -1309,9 +1309,9 @@ vtkIdType vtkChartXY::RaisePlot(vtkPlot* plot) vtkIdType plotIndex = this->GetPlotIndex(plot); int corner = this->GetPlotCorner(plot); if (corner < 0 || corner >=4) - { + { return plotIndex; - } + } return this->ChartPrivate->PlotCorners[corner]->Raise(plotIndex); } @@ -1323,9 +1323,9 @@ vtkIdType vtkChartXY::StackPlotAbove(vtkPlot* plot, vtkPlot* under) int corner = this->GetPlotCorner(plot); if (corner < 0 || corner >=4 || underIndex != this->GetPlotCorner(under)) - { + { return plotIndex; - } + } return this->ChartPrivate->PlotCorners[corner]->StackAbove(plotIndex, underIndex); } @@ -1336,9 +1336,9 @@ vtkIdType vtkChartXY::LowerPlot(vtkPlot* plot) vtkIdType plotIndex = this->GetPlotIndex(plot); int corner = this->GetPlotCorner(plot); if (corner < 0 || corner >=4) - { + { return plotIndex; - } + } return this->ChartPrivate->PlotCorners[corner]->Lower(plotIndex); } @@ -1350,9 +1350,9 @@ vtkIdType vtkChartXY::StackPlotUnder(vtkPlot* plot, vtkPlot* above) int corner = this->GetPlotCorner(plot); if (corner < 0 || corner >=4 || corner != this->GetPlotCorner(above)) - { + { return plotIndex; - } + } return this->ChartPrivate->PlotCorners[corner]->StackUnder(plotIndex, aboveIndex); } @@ -1374,24 +1374,24 @@ vtkChartLegend* vtkChartXY::GetLegend() void vtkChartXY::SetTooltip(vtkTooltipItem *tooltip) { if(tooltip == this->Tooltip) - { + { // nothing to change return; - } + } if(this->Tooltip) - { + { // remove current tooltip from scene this->RemoveItem(this->Tooltip); - } + } this->Tooltip = tooltip; if(this->Tooltip) - { + { // add new tooltip to scene this->AddItem(this->Tooltip); - } + } } //----------------------------------------------------------------------------- @@ -1410,13 +1410,13 @@ vtkIdType vtkChartXY::GetNumberOfPlots() vtkAxis* vtkChartXY::GetAxis(int axisIndex) { if (axisIndex < 4) - { + { return this->ChartPrivate->axes[axisIndex]; - } + } else - { + { return NULL; - } + } } //----------------------------------------------------------------------------- @@ -1432,30 +1432,30 @@ void vtkChartXY::RecalculateBounds() // Ensure that the bounds are recalculated this->PlotTransformValid = false; if (this->Scene) - { + { // Mark the scene as dirty this->Scene->SetDirty(true); - } + } } //----------------------------------------------------------------------------- void vtkChartXY::SetSelectionMethod(int method) { if (method == this->SelectionMethod) - { + { return; - } + } if (method == vtkChart::SELECTION_PLOTS) - { + { // Clear the selection on the plots which may be shared between all of them. // Now iterate through the plots to update selection data std::vector::iterator it = this->ChartPrivate->plots.begin(); for ( ; it != this->ChartPrivate->plots.end(); ++it) - { + { (*it)->SetSelection(NULL); - } } + } Superclass::SetSelectionMethod(method); } @@ -1463,21 +1463,21 @@ void vtkChartXY::SetSelectionMethod(int method) bool vtkChartXY::Hit(const vtkContextMouseEvent &mouse) { if (!this->Interactive) - { + { return false; - } + } vtkVector2i pos(mouse.GetScreenPos()); if (pos[0] > this->Point1[0] && pos[0] < this->Point2[0] && pos[1] > this->Point1[1] && pos[1] < this->Point2[1]) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -1493,15 +1493,15 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) { // Iterate through each corner, and check for a nearby point for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { if (this->ChartPrivate->PlotCorners[i]->MouseMoveEvent(mouse)) - { + { return true; - } } + } if (mouse.GetButton() == this->Actions.Pan()) - { + { // Figure out how much the mouse has moved by in plot coordinates - pan vtkVector2d screenPos(mouse.GetScreenPos().Cast().GetData()); vtkVector2d lastScreenPos(mouse.GetLastScreenPos().Cast().GetData()); @@ -1532,7 +1532,7 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) yAxis->SetMaximum(yAxis->GetMaximum() + delta[1]); if (this->ChartPrivate->PlotCorners.size() == 2) - { + { // Figure out the right axis position, if greater than 2 both will be done // in the else if block below. screenPos = vtkVector2d(mouse.GetScreenPos().Cast().GetData()); @@ -1554,9 +1554,9 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) std::max(delta[1], yAxis->GetMinimumLimit() - yAxis->GetMinimum()); yAxis->SetMinimum(yAxis->GetMinimum() + delta[1]); yAxis->SetMaximum(yAxis->GetMaximum() + delta[1]); - } + } else if (this->ChartPrivate->PlotCorners.size() > 2) - { + { // Figure out the right and top axis positions. // Go from screen to scene coordinates to work out the delta screenPos = vtkVector2d(mouse.GetScreenPos().Cast().GetData()); @@ -1584,24 +1584,24 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) xAxis->SetMaximum(xAxis->GetMaximum() + delta[0]); yAxis->SetMinimum(yAxis->GetMinimum() + delta[1]); yAxis->SetMaximum(yAxis->GetMaximum() + delta[1]); - } + } this->RecalculatePlotTransforms(); // Mark the scene as dirty this->Scene->SetDirty(true); this->InvokeEvent(vtkCommand::InteractionEvent); - } + } else if (mouse.GetButton() == this->Actions.Zoom() || mouse.GetButton() == this->Actions.Select()) - { + { this->MouseBox.SetWidth(mouse.GetPos().GetX() - this->MouseBox.GetX()); this->MouseBox.SetHeight(mouse.GetPos().GetY() - this->MouseBox.GetY()); // Mark the scene as dirty this->Scene->SetDirty(true); - } + } else if (mouse.GetButton() == this->Actions.ZoomAxis()) - { + { vtkVector2d screenPos(mouse.GetScreenPos().Cast().GetData()); vtkVector2d lastScreenPos(mouse.GetLastScreenPos().Cast().GetData()); @@ -1613,12 +1613,12 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) }; for(int i = 0; i < 4; i++) - { + { vtkAxis *axis = axes[i]; if(!axis) - { + { continue; - } + } // bottom, top -> 0, right, left -> 1 int side = i % 2; @@ -1626,9 +1626,9 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) // get mouse delta in the given direction for the axis double delta = lastScreenPos[side] - screenPos[side]; if(std::abs(delta) == 0) - { + { continue; - } + } // scale and invert delta delta /= -100.0; @@ -1638,51 +1638,51 @@ bool vtkChartXY::MouseMoveEvent(const vtkContextMouseEvent &mouse) double max = axis->GetMaximum(); double frac = (max - min) * 0.1; if (frac > 0.0) - { + { min += delta*frac; max -= delta*frac; - } + } else - { + { min -= delta*frac; max += delta*frac; - } + } axis->SetMinimum(min); axis->SetMaximum(max); axis->RecalculateTickSpacing(); - } + } this->RecalculatePlotTransforms(); // Mark the scene as dirty this->Scene->SetDirty(true); - } + } else if (mouse.GetButton() == this->Actions.SelectPolygon()) - { + { if(this->SelectionPolygon.GetNumberOfPoints() > 0) - { + { vtkVector2f lastPoint = this->SelectionPolygon.GetPoint( this->SelectionPolygon.GetNumberOfPoints() - 1); if((lastPoint - mouse.GetPos()).SquaredNorm() > 100) - { + { this->SelectionPolygon.AddPoint(mouse.GetPos()); - } + } // Mark the scene as dirty this->Scene->SetDirty(true); - } } + } else if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON) - { + { this->Scene->SetDirty(true); if(this->Tooltip) - { + { this->Tooltip->SetVisible(this->LocatePointInPlots(mouse)); - } } + } return true; } @@ -1695,19 +1695,19 @@ int vtkChartXY::LocatePointInPlot(const vtkVector2f &position, vtkIdType &segmentIndex) { if (plot && plot->GetVisible()) - { + { vtkPlotBar* plotBar = vtkPlotBar::SafeDownCast(plot); if (plotBar) - { + { // If the plot is a vtkPlotBar, get the segment index too return plotBar->GetNearestPoint(position, tolerance, &plotPos, &segmentIndex); - } + } else - { + { return plot->GetNearestPoint(position, tolerance, &plotPos); - } } + } return -1; } @@ -1721,14 +1721,14 @@ bool vtkChartXY::LocatePointInPlots(const vtkContextMouseEvent &mouse, pos[0] < this->Point2[0] && pos[1] > this->Point1[1] && pos[1] < this->Point2[1] && n) - { + { // Iterate through each corner, and check for a nearby point for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { int items = static_cast(this->ChartPrivate->PlotCorners[i] ->GetNumberOfItems()); if (items) - { + { vtkVector2f plotPos, position; vtkTransform2D* transform = this->ChartPrivate->PlotCorners[i]->GetTransform(); @@ -1742,13 +1742,13 @@ bool vtkChartXY::LocatePointInPlots(const vtkContextMouseEvent &mouse, vtkIdType segmentIndex = -1; for (int j = items-1; j >= 0; --j) - { + { vtkPlot* plot = vtkPlot::SafeDownCast(this->ChartPrivate-> PlotCorners[i]->GetItem(j)); int seriesIndex = LocatePointInPlot(position, tolerance, plotPos, plot, segmentIndex); if (seriesIndex >= 0) - { + { // We found a point, set up the tooltip and return vtkRectd ss(plot->GetShiftScale()); vtkVector2d plotPosd(plotPos[0] / ss[2] - ss[0], @@ -1756,7 +1756,7 @@ bool vtkChartXY::LocatePointInPlots(const vtkContextMouseEvent &mouse, this->SetTooltipInfo(mouse, plotPosd, seriesIndex, plot, segmentIndex); if (invokeEvent >= 0) - { + { vtkChartPlotData plotIndex; plotIndex.SeriesName = plot->GetLabel(); plotIndex.Position = plotPos; @@ -1766,26 +1766,26 @@ bool vtkChartXY::LocatePointInPlots(const vtkContextMouseEvent &mouse, this->InvokeEvent(invokeEvent, static_cast(&plotIndex)); if (invokeEvent == vtkCommand::SelectionChangedEvent) - { + { // Construct a new selection with the selected point in it. vtkNew selectionIds; selectionIds->InsertNextValue(seriesIndex); plot->SetSelection(selectionIds.GetPointer()); if (this->AnnotationLink) - { + { vtkChartSelectionHelper::MakeSelection(this->AnnotationLink, selectionIds.GetPointer(), plot); - } } } - return true; } + return true; } } } } + } return false; } @@ -1796,9 +1796,9 @@ void vtkChartXY::SetTooltipInfo(const vtkContextMouseEvent& mouse, vtkIdType segmentIndex) { if (!this->Tooltip) - { + { return; - } + } // Have the plot generate its tooltip label vtkStdString tooltipLabel = plot->GetTooltipLabel(plotPos, seriesIndex, @@ -1816,9 +1816,9 @@ bool vtkChartXY::MouseLeaveEvent(const vtkContextMouseEvent &) this->DrawNearestPoint = false; if(this->Tooltip) - { + { this->Tooltip->SetVisible(false); - } + } return true; } @@ -1827,55 +1827,55 @@ bool vtkChartXY::MouseLeaveEvent(const vtkContextMouseEvent &) bool vtkChartXY::MouseButtonPressEvent(const vtkContextMouseEvent &mouse) { if(this->Tooltip) - { + { this->Tooltip->SetVisible(false); - } + } // Iterate through each corner, and check for a nearby point for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { if (this->ChartPrivate->PlotCorners[i]->MouseButtonPressEvent(mouse)) - { + { return true; - } } + } if (mouse.GetButton() == this->Actions.Pan()) - { + { // The mouse panning action. this->MouseBox.Set(mouse.GetPos().GetX(), mouse.GetPos().GetY(), 0.0, 0.0); this->DrawBox = false; return true; - } + } else if (mouse.GetButton() == this->Actions.Zoom() || mouse.GetButton() == this->Actions.Select()) - { + { // Selection, for now at least... this->MouseBox.Set(mouse.GetPos().GetX(), mouse.GetPos().GetY(), 0.0, 0.0); this->DrawBox = true; return true; - } + } else if (mouse.GetButton() == this->Actions.ZoomAxis()) - { + { this->MouseBox.Set(mouse.GetPos().GetX(), mouse.GetPos().GetY(), 0.0, 0.0); this->DrawBox = false; return true; - } + } else if (mouse.GetButton() == this->Actions.SelectPolygon()) - { + { this->SelectionPolygon.Clear(); this->SelectionPolygon.AddPoint(mouse.GetPos()); this->DrawSelectionPolygon = true; return true; - } + } else if (mouse.GetButton() == this->ActionsClick.Select() || mouse.GetButton() == this->ActionsClick.Notify()) - { + { return true; - } + } else - { + { return false; - } + } } //----------------------------------------------------------------------------- @@ -1883,44 +1883,44 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) { // Iterate through each corner, and check for a nearby point for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { if (this->ChartPrivate->PlotCorners[i]->MouseButtonReleaseEvent(mouse)) - { + { return true; - } } + } if (mouse.GetButton() > vtkContextMouseEvent::NO_BUTTON && mouse.GetButton() <= vtkContextMouseEvent::RIGHT_BUTTON) - { + { this->MouseBox.SetWidth(mouse.GetPos().GetX() - this->MouseBox.GetX()); this->MouseBox.SetHeight(mouse.GetPos().GetY() - this->MouseBox.GetY()); if ((fabs(this->MouseBox.GetWidth()) < 0.5 && fabs(this->MouseBox.GetHeight()) < 0.5) && (mouse.GetButton() == this->Actions.Select() || mouse.GetButton() == this->Actions.Pan())) - { + { // Invalid box size - treat as a single clicke event this->MouseBox.SetWidth(0.0); this->MouseBox.SetHeight(0.0); this->DrawBox = false; if (mouse.GetButton() == this->ActionsClick.Notify()) - { + { this->LocatePointInPlots(mouse, vtkCommand::InteractionEvent); return true; - } + } else if (mouse.GetButton() == this->ActionsClick.Select()) - { + { this->LocatePointInPlots(mouse, vtkCommand::SelectionChangedEvent); return true; - } + } else - { + { return false; - } } } + } if (mouse.GetButton() == this->Actions.Select() || mouse.GetButton() == this->Actions.SelectPolygon()) - { + { // Modifiers or selection modes can affect how selection is performed. int selectionMode = vtkChartSelectionHelper::GetMouseSelectionMode(mouse, @@ -1930,32 +1930,32 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) // Update the polygon or box with the last mouse position. if (polygonMode) - { + { this->SelectionPolygon.AddPoint(mouse.GetPos()); this->DrawSelectionPolygon = false; - } + } else - { + { this->MouseBox.SetWidth(mouse.GetPos().GetX() - this->MouseBox.GetX()); this->MouseBox.SetHeight(mouse.GetPos().GetY() - this->MouseBox.GetY()); this->DrawBox = false; - } + } // Check whether we have a valid selection area, exit early if not. if (polygonMode && this->SelectionPolygon.GetNumberOfPoints() < 3) - { + { // There is no polygon to select points in. this->SelectionPolygon.Clear(); return true; - } + } else if (fabs(this->MouseBox.GetWidth()) < 0.5 || fabs(this->MouseBox.GetHeight()) < 0.5) - { + { // The box is too small, and no useful selection can be made. this->MouseBox.SetWidth(0.0); this->MouseBox.SetHeight(0.0); return true; - } + } // Iterate through the plots and build a selection. Two main behaviors are // supported - row-based selections add all rows from all plots and set that @@ -1964,15 +1964,15 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) vtkNew oldSelection; vtkNew accumulateSelection; if (this->SelectionMethod == vtkChart::SELECTION_ROWS) - { + { // There is only one global selection, we build up a union of all rows // selected in all charts and set that on all plots. for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { int items = static_cast(this->ChartPrivate->PlotCorners[i] ->GetNumberOfItems()); if (items) - { + { vtkTransform2D *transform = this->ChartPrivate->PlotCorners[i]->GetTransform(); vtkVector2f min; @@ -1983,25 +1983,25 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) // Iterate through the plots and create the selection. for (int j = 0; j < items; ++j) - { + { vtkPlot* plot = vtkPlot::SafeDownCast(this->ChartPrivate-> PlotCorners[i]->GetItem(j)); if (plot && plot->GetVisible() && plot->GetSelectable()) - { + { // There is only really one old selection in this mode. if (i == 0 && j == 0) - { + { oldSelection->DeepCopy(plot->GetSelection()); - } + } // Populate the selection using the appropriate shape. if (polygonMode) - { + { plot->SelectPointsInPolygon(polygon); - } + } else - { + { plot->SelectPoints(min, max); - } + } // Accumulate the selection in each plot. vtkChartSelectionHelper::BuildSelection(0, @@ -2009,26 +2009,26 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) accumulateSelection.GetPointer(), plot->GetSelection(), 0); - } } } } + } // Now add the accumulated selection to the old selection. vtkChartSelectionHelper::BuildSelection(this->AnnotationLink, selectionMode, accumulateSelection.GetPointer(), oldSelection.GetPointer(), 0); - } + } else if (this->SelectionMethod == vtkChart::SELECTION_PLOTS) - { + { // We are performing plot based selections. for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { int items = static_cast(this->ChartPrivate->PlotCorners[i] ->GetNumberOfItems()); if (items) - { + { vtkTransform2D *transform = this->ChartPrivate->PlotCorners[i]->GetTransform(); vtkVector2f min; @@ -2038,21 +2038,21 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) min, max, polygon); for (int j = 0; j < items; ++j) - { + { vtkPlot* plot = vtkPlot::SafeDownCast(this->ChartPrivate-> PlotCorners[i]->GetItem(j)); if (plot && plot->GetVisible() && plot->GetSelectable()) - { + { oldSelection->DeepCopy(plot->GetSelection()); // Populate the selection using the appropriate shape. if (polygonMode) - { + { plot->SelectPointsInPolygon(polygon); - } + } else - { + { plot->SelectPoints(min, max); - } + } // Combine the selection in this plot with any previous selection. vtkChartSelectionHelper::BuildSelection(this->AnnotationLink, @@ -2060,33 +2060,33 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) plot->GetSelection(), oldSelection.GetPointer(), plot); - } } } } } + } else if (this->SelectionMethod == vtkChart::SELECTION_COLUMNS) - { + { if (this->AnnotationLink) - { + { this->AnnotationLink->Update(); vtkSelection *selection = vtkSelection::SafeDownCast(this->AnnotationLink->GetOutputDataObject(2)); vtkSelectionNode *node = selection->GetNumberOfNodes() > 0? selection->GetNode(0) : NULL; if (node) - { + { oldSelection->DeepCopy(vtkArrayDownCast(node->GetSelectionList())); - } } + } vtkNew plotSelection; // We are performing plot based selections. for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { int items = static_cast(this->ChartPrivate->PlotCorners[i] ->GetNumberOfItems()); if (items) - { + { vtkTransform2D *transform = this->ChartPrivate->PlotCorners[i]->GetTransform(); vtkVector2f min; @@ -2096,44 +2096,44 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) min, max, polygon); for (int j = 0; j < items; ++j) - { + { vtkPlot* plot = vtkPlot::SafeDownCast(this->ChartPrivate-> PlotCorners[i]->GetItem(j)); if (plot && plot->GetVisible() && plot->GetSelectable()) - { + { bool selected = false; // Populate the selection using the appropriate shape. if (polygonMode) - { + { selected = plot->SelectPointsInPolygon(polygon); - } + } else - { + { selected = plot->SelectPoints(min, max); - } + } vtkNew plotsSelection; if (selected) - { + { int idx = 1; // y vtkAbstractArray* column = plot->GetData()->GetInputAbstractArrayToProcess( idx, plot->GetInput()); int columnID = -1; plot->GetInput()->GetRowData()->GetAbstractArray(column->GetName(), columnID); if (plotSelection->GetNumberOfTuples() != column->GetNumberOfTuples()) - { + { plotSelection->SetNumberOfTuples(0); for (vtkIdType k = 0; k < column->GetNumberOfTuples(); ++k) - { + { plotSelection->InsertNextValue(k); - } } + } plot->SetSelection(plotSelection.GetPointer()); accumulateSelection->InsertNextValue(columnID); - } } } } } + } vtkIdType* ptrSelection = reinterpret_cast(accumulateSelection->GetVoidPointer(0)); std::sort(ptrSelection, ptrSelection + accumulateSelection->GetNumberOfTuples()); @@ -2143,24 +2143,24 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) accumulateSelection.GetPointer(), oldSelection.GetPointer(), 0); - } + } this->InvokeEvent(vtkCommand::SelectionChangedEvent); this->MouseBox.SetWidth(0.0); this->MouseBox.SetHeight(0.0); this->SelectionPolygon.Clear(); return true; - } + } else if (mouse.GetButton() == this->Actions.Zoom()) - { + { // Check whether a valid zoom box was drawn if (fabs(this->MouseBox.GetWidth()) < 0.5 || fabs(this->MouseBox.GetHeight()) < 0.5) - { + { // Invalid box size - do nothing this->MouseBox.SetWidth(0.0); this->MouseBox.SetHeight(0.0); this->DrawBox = false; return true; - } + } // Zoom into the chart by the specified amount, and recalculate the bounds vtkVector2f point2(mouse.GetPos()); @@ -2180,11 +2180,11 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) this->Scene->SetDirty(true); this->InvokeEvent(vtkCommand::InteractionEvent); return true; - } + } else if (mouse.GetButton() == this->Actions.ZoomAxis()) - { + { return true; - } + } return false; } @@ -2201,25 +2201,25 @@ void vtkChartXY::ZoomInAxes(vtkAxis *x, vtkAxis *y, float *originf, float *maxf) // Ensure we preserve the directionality of the axes if (x->GetMaximum() > x->GetMinimum()) - { + { x->SetMaximum(torigin[0] > tmax[0] ? torigin[0] : tmax[0]); x->SetMinimum(torigin[0] < tmax[0] ? torigin[0] : tmax[0]); - } + } else - { + { x->SetMaximum(torigin[0] < tmax[0] ? torigin[0] : tmax[0]); x->SetMinimum(torigin[0] > tmax[0] ? torigin[0] : tmax[0]); - } + } if (y->GetMaximum() > y->GetMinimum()) - { + { y->SetMaximum(torigin[1] > tmax[1] ? torigin[1] : tmax[1]); y->SetMinimum(torigin[1] < tmax[1] ? torigin[1] : tmax[1]); - } + } else - { + { y->SetMaximum(torigin[1] < tmax[1] ? torigin[1] : tmax[1]); y->SetMinimum(torigin[1] > tmax[1] ? torigin[1] : tmax[1]); - } + } x->RecalculateTickSpacing(); y->RecalculateTickSpacing(); } @@ -2228,35 +2228,35 @@ void vtkChartXY::ZoomInAxes(vtkAxis *x, vtkAxis *y, float *originf, float *maxf) bool vtkChartXY::MouseWheelEvent(const vtkContextMouseEvent &, int delta) { if(this->Tooltip) - { + { this->Tooltip->SetVisible(false); - } + } if (!this->ZoomWithMouseWheel) - { + { return false; - } + } // Get the bounds of each plot. for (int i = 0; i < 4; ++i) - { + { vtkAxis *axis = this->ChartPrivate->axes[i]; double min = axis->GetMinimum(); double max = axis->GetMaximum(); double frac = (max - min) * 0.1; if (frac > 0.0) - { + { min += delta*frac; max -= delta*frac; - } + } else - { + { min -= delta*frac; max += delta*frac; - } + } axis->SetMinimum(min); axis->SetMaximum(max); axis->RecalculateTickSpacing(); - } + } this->RecalculatePlotTransforms(); @@ -2272,13 +2272,13 @@ bool vtkChartXY::MouseWheelEvent(const vtkContextMouseEvent &, int delta) bool vtkChartXY::KeyPressEvent(const vtkContextKeyEvent &key) { switch (key.GetKeyCode()) - { + { // Reset the chart axes case 'r': case 'R': this->RecalculateBounds(); this->Scene->SetDirty(true); - } + } return true; } @@ -2288,12 +2288,12 @@ bool vtkChartXY::RemovePlotFromCorners(vtkPlot *plot) { // We know the plot will only ever be in one of the corners for (size_t i = 0; i < this->ChartPrivate->PlotCorners.size(); ++i) - { + { if (this->ChartPrivate->PlotCorners[i]->RemoveItem(plot)) - { + { return true; - } } + } return false; } @@ -2305,33 +2305,33 @@ inline void vtkChartXY::TransformBoxOrPolygon(bool polygonMode, vtkContextPolygon &polygon) { if (polygonMode) - { + { vtkNew inverseTransform; inverseTransform->SetMatrix(transform->GetMatrix()); inverseTransform->Inverse(); polygon = this->SelectionPolygon.Transformed(inverseTransform.GetPointer()); - } + } else - { + { transform->InverseTransformPoints(this->MouseBox.GetData(), min.GetData(), 1); transform->InverseTransformPoints(mousePosition.GetData(), max.GetData(), 1); // Normalize the rectangle selection area before using it. if (min.GetX() > max.GetX()) - { + { float tmp = min.GetX(); min.SetX(max.GetX()); max.SetX(tmp); - } + } if (min.GetY() > max.GetY()) - { + { float tmp = min.GetY(); min.SetY(max.GetY()); max.SetY(tmp); - } } + } } //----------------------------------------------------------------------------- @@ -2340,19 +2340,19 @@ void vtkChartXY::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "Axes: " << endl; for (int i = 0; i < 4; ++i) - { + { this->ChartPrivate->axes[i]->PrintSelf(os, indent.GetNextIndent()); - } + } if (this->ChartPrivate) - { + { os << indent << "Number of plots: " << this->ChartPrivate->plots.size() << endl; for (unsigned int i = 0; i < this->ChartPrivate->plots.size(); ++i) - { + { os << indent << "Plot " << i << ":" << endl; this->ChartPrivate->plots[i]->PrintSelf(os, indent.GetNextIndent()); - } } + } os << indent << "ZoomWithMouseWheel: " << this->ZoomWithMouseWheel << endl; } diff --git a/Charts/Core/vtkChartXYZ.cxx b/Charts/Core/vtkChartXYZ.cxx index 9d0078afef0..ace551db907 100644 --- a/Charts/Core/vtkChartXYZ.cxx +++ b/Charts/Core/vtkChartXYZ.cxx @@ -66,10 +66,10 @@ vtkChartXYZ::vtkChartXYZ() : Geometry(0, 0, 10, 10), IsX(false), Angle(0) this->FitToScene = true; this->Axes.resize(3); for(unsigned int i = 0; i < 3; ++i) - { + { vtkNew axis; this->Axes[i] = axis.GetPointer(); - } + } } //----------------------------------------------------------------------------- @@ -105,10 +105,10 @@ void vtkChartXYZ::SetDecorateAxes(bool b) void vtkChartXYZ::SetAnnotationLink(vtkAnnotationLink *link) { if (this->Link != link) - { + { this->Link = link; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -150,24 +150,24 @@ void vtkChartXYZ::SetGeometry(const vtkRectf &bounds) this->Axes[2]->SetPoint1(vtkVector2f(this->Geometry.GetX(), 0)); if (this->IsX) - { + { this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(), this->Geometry.GetHeight())); - } + } else - { + { this->Axes[2]->SetPoint2(vtkVector2f(this->Geometry.GetX(), this->Geometry.GetWidth())); - } + } } //----------------------------------------------------------------------------- void vtkChartXYZ::RecalculateBounds() { if (this->Plots.empty()) - { + { return; - } + } double bounds[] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, @@ -175,28 +175,28 @@ void vtkChartXYZ::RecalculateBounds() // Need to calculate the bounds in three dimensions and set up the axes. for (unsigned int i = 0; i < this->Plots.size(); ++i) - { + { std::vector const& points = this->Plots[i]->GetPoints(); for (unsigned int j = 0; j < points.size(); ++j) - { + { const vtkVector3f &v = points[j]; for (int k = 0; k < 3; ++k) - { + { if (v[k] < bounds[2 * k]) - { + { bounds[2 * k] = v[k]; - } + } if (v[k] > bounds[2 * k + 1]) - { + { bounds[2 * k + 1] = v[k]; - } } } } + } for (int i = 0; i < 3; ++i) - { + { this->Axes[i]->SetUnscaledRange(&bounds[2*i]); - } + } // Recalculate transform since axes' ranges were modified this->RecalculateTransform(); @@ -212,20 +212,20 @@ void vtkChartXYZ::PrintSelf(ostream &os, vtkIndent indent) void vtkChartXYZ::Update() { if (this->Link) - { + { vtkSelection *selection = vtkSelection::SafeDownCast(this->Link->GetOutputDataObject(2)); if (selection->GetNumberOfNodes()) - { + { vtkSelectionNode *node = selection->GetNode(0); vtkIdTypeArray *idArray = vtkArrayDownCast(node->GetSelectionList()); for (size_t i = 0; i < this->Plots.size(); ++i) - { + { this->Plots[i]->SetSelection(idArray); - } } } + } } //----------------------------------------------------------------------------- @@ -247,20 +247,20 @@ bool vtkChartXYZ::Paint(vtkContext2D *painter) // Check if the scene changed size bool resizeHappened = false; if (this->FitToScene) - { + { resizeHappened = this->CheckForSceneResize(); - } + } // Calculate the transforms required for the current rotation. this->CalculateTransforms(); // Set up clipping planes for (int i = 0; i < 6; i++) - { + { double planeEquation[4]; this->GetClippingPlaneEquation(i, planeEquation); context->EnableClippingPlane(i, planeEquation); - } + } // Draw plots context->PushMatrix(); @@ -269,9 +269,9 @@ bool vtkChartXYZ::Paint(vtkContext2D *painter) // Remove clipping planes for (int i = 0; i < 6; i++) - { + { context->DisableClippingPlane(i); - } + } // Calculate the bounds of the data within the axes this->ComputeDataBounds(); @@ -282,17 +282,17 @@ bool vtkChartXYZ::Paint(vtkContext2D *painter) // Draw the axes, tick marks, and labels this->DrawAxes(context); if(this->DrawAxesDecoration) - { + { this->DetermineWhichAxesToLabel(); this->DrawTickMarks(painter); this->DrawAxesLabels(painter); - } + } // If necessary, rescale the axes so they fits our scene nicely if (resizeHappened) - { + { this->RescaleAxes(); - } + } return true; } @@ -314,9 +314,9 @@ void vtkChartXYZ::DrawAxes(vtkContext3D *context) context->DrawLine(box[2], box[3]); context->DrawLine(box[3], box[0]); for (int i = 0; i < 4; ++i) - { + { box[i].SetZ(1); - } + } context->DrawLine(box[0], box[1]); context->DrawLine(box[1], box[2]); context->DrawLine(box[2], box[3]); @@ -337,33 +337,33 @@ void vtkChartXYZ::ComputeDataBounds() float transformedPoint[3]; for (unsigned int i = 0; i < this->Plots.size(); ++i) - { + { vtkPlot3D *plot = this->Plots[i]; // examine the eight corners of this plot's bounding cube for (unsigned int j = 0; j < 8; ++j) - { + { this->ContextTransform->TransformPoint( plot->GetDataBounds()[j].GetData(), transformedPoint); if (transformedPoint[0] < xMin) - { + { xMin = transformedPoint[0]; - } + } if (transformedPoint[0] > xMax) - { + { xMax = transformedPoint[0]; - } + } if (transformedPoint[1] < yMin) - { + { yMin = transformedPoint[1]; - } + } if (transformedPoint[1] > yMax) - { + { yMax = transformedPoint[1]; - } } } + } this->DataBounds[0] = xMin; this->DataBounds[1] = yMin; @@ -389,7 +389,7 @@ void vtkChartXYZ::DrawAxesLabels(vtkContext2D *painter) // corresponding label bool shouldDrawAxis[3]; for (int axis = 0; axis < 3; ++axis) - { + { shouldDrawAxis[axis] = true; float start[3] = { 0, 0, 0 }; float end[3] = { 0, 0, 0 }; @@ -400,10 +400,10 @@ void vtkChartXYZ::DrawAxesLabels(vtkContext2D *painter) (end[0] - start[0]) * (end[0] - start[0]) + (end[1] - start[1]) * (end[1] - start[1])); if (axisLength == 0) - { + { shouldDrawAxis[axis] = false; - } } + } float bounds[4]; float xLabelPos[3]; @@ -413,40 +413,40 @@ void vtkChartXYZ::DrawAxesLabels(vtkContext2D *painter) // calculate the pixel coordinates of the lines we wish to label if (shouldDrawAxis[0]) - { + { xLabelPos[0] = 0.5; xLabelPos[1] = this->XAxisToLabel[0]; xLabelPos[2] = this->XAxisToLabel[1]; this->Box->TransformPoint(xLabelPos, xLabelPos); - } + } if (shouldDrawAxis[1]) - { + { yLabelPos[0] = this->YAxisToLabel[0]; yLabelPos[1] = 0.5; yLabelPos[2] = this->YAxisToLabel[1]; this->Box->TransformPoint(yLabelPos, yLabelPos); - } + } if (shouldDrawAxis[2]) - { + { zLabelPos[0] = this->ZAxisToLabel[0]; zLabelPos[1] = this->ZAxisToLabel[1]; zLabelPos[2] = 0.5; this->Box->TransformPoint(zLabelPos, zLabelPos); - } + } context->PopMatrix(); if (shouldDrawAxis[0]) - { + { painter->ComputeStringBounds(this->XAxisLabel, bounds); this->GetOffsetForAxisLabel(0, bounds, offset); xLabelPos[0] += (offset[0] + this->TickLabelOffset[0][0]); xLabelPos[1] += (offset[1] + this->TickLabelOffset[0][1]); painter->DrawString(xLabelPos[0], xLabelPos[1], this->XAxisLabel); - } + } if (shouldDrawAxis[1]) - { + { painter->ComputeStringBounds(this->YAxisLabel, bounds); offset[0] = 0; offset[1] = 0; @@ -454,10 +454,10 @@ void vtkChartXYZ::DrawAxesLabels(vtkContext2D *painter) yLabelPos[0] += (offset[0] + this->TickLabelOffset[1][0]); yLabelPos[1] += (offset[1] + this->TickLabelOffset[1][1]); painter->DrawString(yLabelPos[0], yLabelPos[1], this->YAxisLabel); - } + } if (shouldDrawAxis[2]) - { + { painter->ComputeStringBounds(this->ZAxisLabel, bounds); offset[0] = 0; offset[1] = 0; @@ -465,7 +465,7 @@ void vtkChartXYZ::DrawAxesLabels(vtkContext2D *painter) zLabelPos[0] += (offset[0] + this->TickLabelOffset[2][0]); zLabelPos[1] += (offset[1] + this->TickLabelOffset[2][1]); painter->DrawString(zLabelPos[0], zLabelPos[1], this->ZAxisLabel); - } + } } //----------------------------------------------------------------------------- @@ -475,7 +475,7 @@ void vtkChartXYZ::GetOffsetForAxisLabel(int axis, float *bounds, offset[0] = 0; offset[1] = 0; switch (this->DirectionToData[axis]) - { + { // data is to the north // offset is -y case 0: @@ -528,7 +528,7 @@ void vtkChartXYZ::GetOffsetForAxisLabel(int axis, float *bounds, offset[0] = bounds[2]; offset[1] = -bounds[3]; break; - } + } } //----------------------------------------------------------------------------- @@ -542,7 +542,7 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) // treat each axis separately for (int axis = 0; axis < 3; ++axis) - { + { // pop matrix since we'll be drawing text in 2D before we draw the // actual tick marks context->PopMatrix(); @@ -552,7 +552,7 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) double startBox[3] = { 0, 0, 0 }; double endBox[3] = { 0, 0, 0 }; switch (axis) - { + { case 0: startBox[0] = 0; endBox[0] = 1; @@ -572,7 +572,7 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) startBox[2] = 0; endBox[2] = 1; break; - } + } // convert these values to pixel coordinates double start[3]; @@ -589,15 +589,15 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) this->CalculateNiceMinMax(start[axis], end[axis], axis); if (tickSpacing == -1) - { + { continue; - } + } std::vector < vtkVector3f > tickPoints; int currentTick = 0; float tickPositionAlongAxis = start[axis]; while (tickPositionAlongAxis < end[axis]) - { + { vtkVector3f tick; // convert tick position back into box coordinates // during this process, we save the tick position in pixels for labeling @@ -620,7 +620,7 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) tick[axis] = tickPosition[axis]; if (tick[axis] >= startBox[axis] && tick[axis] <= endBox[axis]) - { + { tickPoints.push_back(tick); // get the tick mark label @@ -637,33 +637,33 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter) // we store this offset so we know where to draw the axis label later if (fabs(offset[0]) > fabs(labelOffset[0])) - { + { labelOffset[0] = offset[0]; - } + } if (fabs(offset[1]) > fabs(labelOffset[1])) - { + { labelOffset[1] = offset[1]; - } + } // draw the label for this tick mark painter->DrawString(tickPositionInPixels[0], tickPositionInPixels[1], tickLabel); - } + } ++currentTick; tickPositionAlongAxis = start[axis] + (tickSpacing * currentTick); - } + } // re-apply the Box matrix and draw the tick marks as points if (tickPoints.size() != 0) - { + { context->PushMatrix(); context->AppendTransform(this->Box.GetPointer()); context->DrawPoints(tickPoints[0].GetData(), static_cast(tickPoints.size())); this->TickLabelOffset[axis][0] = labelOffset[0]; this->TickLabelOffset[axis][1] = labelOffset[1]; - } } + } //revert from drawing points. context->ApplyPen(this->AxisPen.GetPointer()); @@ -674,15 +674,15 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() { // for each dimension (XYZ) for (int axis = 0; axis < 3; ++axis) - { + { double maxDistance = -1; // for each of the four "axis" lines corresponding to this dimension for (float i = 0; i < 2; ++i) - { + { for (float j = 0; j < 2; ++j) - { + { for (float k = 0; k < 2; ++k) - { + { // convert this line's midpoint to screen (pixel) coordinates float midpoint[3] = { i, j, k }; midpoint[axis] = 0.5; @@ -695,9 +695,9 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() midpoint[1] > this->DataBounds[1] && midpoint[0] < this->DataBounds[2] && midpoint[1] < this->DataBounds[3]) - { + { switch (axis) - { + { case 0: ++i; break; @@ -709,9 +709,9 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() break; default: break; - } - continue; } + continue; + } // calculate the distance from this line's midpoint to the data range double d = 0; @@ -720,42 +720,42 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() // case 1: midpoint falls within x range (but not y) if (midpoint[0] > this->DataBounds[0] && midpoint[0] < this->DataBounds[2]) - { + { double d1 = fabs(midpoint[1] - this->DataBounds[1]); double d2 = fabs(midpoint[1] - this->DataBounds[3]); if (d1 < d2) - { + { directionToData = 0; // data is "up" from the axis d = d1; - } + } else - { + { directionToData = 4; // data is "down" from the axis d = d2; - } } + } // case 2: midpoint falls within y range (but not x) else if (midpoint[1] > this->DataBounds[1] && midpoint[1] < this->DataBounds[3]) - { + { double d1 = fabs(midpoint[0] - this->DataBounds[0]); double d2 = fabs(midpoint[0] - this->DataBounds[2]); if (d1 < d2) - { + { directionToData = 2; // data is "right" from the axis d = d1; - } + } else - { + { directionToData = 6; // data is "left" from the axis d = d2; - } } + } // case 3: compute distance to nearest corner else - { + { //x min, y min d = sqrt( (this->DataBounds[0] - midpoint[0]) * (this->DataBounds[0] - midpoint[0]) + @@ -770,30 +770,30 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() (this->DataBounds[3] - midpoint[1]) * (this->DataBounds[3] - midpoint[1]) ); if (d0 < d) - { + { d = d0; directionToData = 3; // data is to the southeast - } + } //x max, y min d0 = sqrt( (this->DataBounds[2] - midpoint[0]) * (this->DataBounds[2] - midpoint[0]) + (this->DataBounds[1] - midpoint[1]) * (this->DataBounds[1] - midpoint[1]) ); if (d0 < d) - { + { d = d0; directionToData = 7; // data is to the northwest - } + } //x max, y max d0 = sqrt( (this->DataBounds[2] - midpoint[0]) * (this->DataBounds[2] - midpoint[0]) + (this->DataBounds[3] - midpoint[1]) * (this->DataBounds[3] - midpoint[1]) ); if (d0 < d) - { + { d = d0; directionToData = 5; // data is to the southwest - } + } // Test if the data falls within the bounds of our axis line, // despite the fact that it is diagonal from the line's midpoint. @@ -808,41 +808,41 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() this->Box->TransformPoint(end, end); if (start[0] < this->DataBounds[0] && end[0] > this->DataBounds[2]) - { + { // data falls within horizontal range of this axis line // set directionToData as purely up or purely down if (directionToData == 1 || directionToData == 7) - { + { directionToData = 0; - } + } else - { + { directionToData = 4; - } - } + } + } else if (start[1] < this->DataBounds[1] && end[1] > this->DataBounds[3]) - { + { // data falls within vertical range of this axis line // set directionToData as purely left or purely right if (directionToData == 1 || directionToData == 3) - { + { directionToData = 2; - } + } else - { + { directionToData = 6; - } - } + } } + } // record this axis line if it has the greatest distance to the data if (d > maxDistance) - { + { this->DirectionToData[axis] = directionToData; maxDistance = d; switch (axis) - { + { case 0: this->XAxisToLabel[0] = static_cast(j); this->XAxisToLabel[1] = static_cast(k); @@ -856,35 +856,35 @@ void vtkChartXYZ::DetermineWhichAxesToLabel() this->ZAxisToLabel[0] = static_cast(i); this->ZAxisToLabel[1] = static_cast(j); break; - } } + } // these three cases keep us from evaluating the same line twice. if (axis == 2) - { + { ++k; - } } + } if (axis == 1) - { + { ++j; - } } + } if (axis == 0) - { + { ++i; - } } } + } } //----------------------------------------------------------------------------- bool vtkChartXYZ::Hit(const vtkContextMouseEvent& vtkNotUsed(mouse)) { if (!this->Interactive || !this->Visible || this->AutoRotate) - { + { return false; - } + } return true; } @@ -894,9 +894,9 @@ bool vtkChartXYZ::MouseButtonPressEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { return true; - } + } return false; } @@ -904,27 +904,27 @@ bool vtkChartXYZ::MouseButtonPressEvent(const vtkContextMouseEvent bool vtkChartXYZ::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { if (mouse.GetModifiers() == vtkContextMouseEvent::SHIFT_MODIFIER) - { + { return this->Spin(mouse); - } + } else - { + { return this->Rotate(mouse); - } } + } if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON) - { + { if (mouse.GetModifiers() == vtkContextMouseEvent::SHIFT_MODIFIER) - { + { return this->Pan(mouse); - } + } else - { + { return this->Zoom(mouse); - } } + } return false; } @@ -959,9 +959,9 @@ bool vtkChartXYZ::Rotate(const vtkContextMouseEvent &mouse) // avoid NaNs in our transformation matrix if the scene has not yet been // rendered. if (this->Scene->GetSceneHeight() == 0 || this->Scene->GetSceneWidth() == 0) - { + { return false; - } + } // Figure out how much the mouse has moved in plot coordinates vtkVector2d screenPos(mouse.GetScreenPos().Cast().GetData()); @@ -1014,11 +1014,11 @@ bool vtkChartXYZ::Zoom(const vtkContextMouseEvent &mouse) float delta = 0.0f; if (this->Scene->GetSceneHeight() > 0) - { + { delta = static_cast( mouse.GetLastScreenPos()[1] - mouse.GetScreenPos()[1]) / this->Scene->GetSceneHeight(); - } + } // Dragging full screen height zooms 4x. float scaling = pow(4.0f, delta); @@ -1056,7 +1056,7 @@ bool vtkChartXYZ::Spin(const vtkContextMouseEvent &mouse) bool vtkChartXYZ::KeyPressEvent(const vtkContextKeyEvent &key) { switch (key.GetKeyCode()) - { + { // Change view to 2D, YZ chart case 'x': this->LookDownX(); @@ -1078,7 +1078,7 @@ bool vtkChartXYZ::KeyPressEvent(const vtkContextKeyEvent &key) case 'Z': this->LookUpZ(); break; - } + } return true; } @@ -1156,16 +1156,16 @@ void vtkChartXYZ::CalculateTransforms() this->ContextTransform->Concatenate(this->Rotation.GetPointer()); this->ContextTransform->Concatenate(this->BoxScale.GetPointer()); if (this->AutoRotate) - { + { if (this->IsX) - { + { this->ContextTransform->RotateX(this->Angle); - } + } else - { + { this->ContextTransform->RotateY(this->Angle); - } } + } this->ContextTransform->Concatenate(this->Scale.GetPointer()); this->ContextTransform->Translate(mtranslation.GetData()); this->ContextTransform->Translate( @@ -1177,18 +1177,18 @@ void vtkChartXYZ::CalculateTransforms() // Next construct the transform for the box axes. double scale[3] = { 300, 300, 300 }; for (int i = 0; i < 3; ++i) - { + { if (i == 0) - { + { scale[i] = this->Axes[i]->GetPosition2()[0] - this->Axes[i]->GetPosition1()[0]; - } + } else - { + { scale[i] = this->Axes[i]->GetPosition2()[1] - this->Axes[i]->GetPosition1()[1]; - } } + } this->Box->Identity(); this->Box->PostMultiply(); @@ -1196,16 +1196,16 @@ void vtkChartXYZ::CalculateTransforms() this->Box->Concatenate(this->Rotation.GetPointer()); this->Box->Concatenate(this->BoxScale.GetPointer()); if (this->AutoRotate) - { + { if (this->IsX) - { + { this->Box->RotateX(this->Angle); - } + } else - { + { this->Box->RotateY(this->Angle); - } } + } this->Box->Translate(0.5, 0.5, 0.5); this->Box->Scale(scale); this->Box->Translate(Axes[0]->GetPosition1()[0], @@ -1227,9 +1227,9 @@ void vtkChartXYZ::CalculateTransforms() cube[7] = vtkVector3d(1, 1, 1); for (int i = 0; i < 8; ++i) - { + { this->Box->TransformPoint(cube[i].GetData(), transformedCube[i].GetData()); - } + } double norm1[3]; double norm2[3]; @@ -1302,39 +1302,39 @@ void vtkChartXYZ::ScaleUpAxes() bool shouldScaleUp = true; while (shouldScaleUp) - { + { for (int i = 0; i < 14; ++i) - { + { point[0] = this->AxesBoundaryPoints[i][0]; point[1] = this->AxesBoundaryPoints[i][1]; point[2] = this->AxesBoundaryPoints[i][2]; this->FutureBox->TransformPoint(point, point); if (point[0] < 0 || point[0] > sceneWidth || point[1] < 0 || point[1] > sceneHeight) - { + { shouldScaleUp = false; - } } + } if (shouldScaleUp) - { + { this->FutureBoxScale->Scale(scaleStep, scaleStep, scaleStep); ++numSteps; if (numSteps > 500) - { + { // Break out of the loop. shouldScaleUp = false; - } } } + } // this while loop overshoots the mark by one step, // so we take a step back afterwards. this->FutureBoxScale->Scale(stepBack, stepBack, stepBack); if (numSteps > 1) - { + { this->ZoomAxes(numSteps - 1); this->Scene->SetDirty(true); - } + } } //----------------------------------------------------------------------------- @@ -1349,37 +1349,37 @@ void vtkChartXYZ::ScaleDownAxes() bool shouldScaleDown = true; while (shouldScaleDown) - { + { shouldScaleDown = false; for (int i = 0; i < 14; ++i) - { + { point[0] = this->AxesBoundaryPoints[i][0]; point[1] = this->AxesBoundaryPoints[i][1]; point[2] = this->AxesBoundaryPoints[i][2]; this->FutureBox->TransformPoint(point, point); if (point[0] < 0 || point[0] > sceneWidth || point[1] < 0 || point[1] > sceneHeight) - { + { shouldScaleDown = true; break; - } } + } if (shouldScaleDown) - { + { this->FutureBoxScale->Scale(scaleStep, scaleStep, scaleStep); ++numSteps; if (numSteps > 500) - { + { // Break out of the loop. shouldScaleDown = false; - } } } + } if (numSteps > 0) - { + { this->ZoomAxes(-numSteps); this->Scene->SetDirty(true); - } + } } //----------------------------------------------------------------------------- @@ -1387,14 +1387,14 @@ void vtkChartXYZ::InitializeFutureBox() { double scale[3] = { 300, 300, 300 }; for (int i = 0; i < 3; ++i) - { + { if (i == 0) scale[i] = this->Axes[i]->GetPosition2()[0] - this->Axes[i]->GetPosition1()[0]; else scale[i] = this->Axes[i]->GetPosition2()[1] - this->Axes[i]->GetPosition1()[1]; - } + } this->FutureBoxScale->DeepCopy(this->BoxScale.GetPointer()); @@ -1417,11 +1417,11 @@ bool vtkChartXYZ::CheckForSceneResize() int currentHeight = this->Scene->GetSceneHeight(); if (this->SceneWidth != currentWidth || this->SceneHeight != currentHeight) - { + { // treat the initial render as a special case, as the scene size // has not been recorded yet if (this->SceneWidth > 0) - { + { int dx = (currentWidth - this->SceneWidth) / 2; int dy = (currentHeight - this->SceneHeight) / 2; @@ -1448,17 +1448,17 @@ bool vtkChartXYZ::CheckForSceneResize() axisPt[0] += dx; this->Axes[2]->SetPoint2(axisPt); this->RecalculateTransform(); - } + } else - { + { this->SceneWidth = currentWidth; this->SceneHeight = currentHeight; this->InitializeFutureBox(); this->ScaleUpAxes(); this->ScaleDownAxes(); - } - return true; } + return true; + } return false; } @@ -1469,13 +1469,13 @@ void vtkChartXYZ::RescaleAxes() int currentHeight = this->Scene->GetSceneHeight(); this->InitializeFutureBox(); if (currentWidth * currentHeight < this->SceneWidth * this->SceneHeight) - { + { this->ScaleDownAxes(); - } + } else - { + { this->ScaleUpAxes(); - } + } this->SceneWidth = currentWidth; this->SceneHeight = currentHeight; } @@ -1485,21 +1485,21 @@ void vtkChartXYZ::InitializeAxesBoundaryPoints() { int currentPoint = 0; for (int i = 0; i < 2; ++i) - { + { for (int j = 0; j < 2; ++j) - { + { for (int k = 0; k < 2; ++k) - { + { this->AxesBoundaryPoints[currentPoint][0] = i; this->AxesBoundaryPoints[currentPoint][1] = j; this->AxesBoundaryPoints[currentPoint][2] = k; ++currentPoint; - } } } + } for (int i = 0; i < 3; ++i) - { + { this->AxesBoundaryPoints[currentPoint][0] = 0.5; this->AxesBoundaryPoints[currentPoint][1] = 0.5; this->AxesBoundaryPoints[currentPoint][2] = 0.5; @@ -1510,7 +1510,7 @@ void vtkChartXYZ::InitializeAxesBoundaryPoints() this->AxesBoundaryPoints[currentPoint][2] = 0.5; this->AxesBoundaryPoints[currentPoint][i] -= sqrt(0.75); ++currentPoint; - } + } } //----------------------------------------------------------------------------- @@ -1553,9 +1553,9 @@ bool vtkChartXYZ::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkAxis *z, float *min = x->GetPoint1(); float *max = x->GetPoint2(); if (fabs(max[0] - min[0]) == 0.0f) - { + { return false; - } + } float xScale = (x->GetUnscaledMaximum() - x->GetUnscaledMinimum()) / (max[0] - min[0]); @@ -1563,9 +1563,9 @@ bool vtkChartXYZ::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkAxis *z, min = y->GetPoint1(); max = y->GetPoint2(); if (fabs(max[1] - min[1]) == 0.0f) - { + { return false; - } + } float yScale = (y->GetUnscaledMaximum() - y->GetUnscaledMinimum()) / (max[1] - min[1]); @@ -1573,9 +1573,9 @@ bool vtkChartXYZ::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkAxis *z, min = z->GetPoint1(); max = z->GetPoint2(); if (fabs(max[1] - min[1]) == 0.0f) - { + { return false; - } + } float zScale = (z->GetUnscaledMaximum() - z->GetUnscaledMinimum()) / (max[1] - min[1]); @@ -1595,9 +1595,9 @@ bool vtkChartXYZ::CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkAxis *z, vtkIdType vtkChartXYZ::AddPlot(vtkPlot3D * plot) { if (plot == NULL) - { + { return -1; - } + } this->AddItem(plot); plot->SetChart(this); this->Plots.push_back(plot); @@ -1605,19 +1605,19 @@ vtkIdType vtkChartXYZ::AddPlot(vtkPlot3D * plot) // the first plot added to the chart defines the names of the axes if (plotIndex == 0) - { + { this->XAxisLabel = plot->GetXAxisLabel(); this->YAxisLabel = plot->GetYAxisLabel(); this->ZAxisLabel = plot->GetZAxisLabel(); - } + } this->RecalculateBounds(); // Mark the scene as dirty if (this->Scene) - { + { this->Scene->SetDirty(true); - } + } return plotIndex; } @@ -1639,7 +1639,7 @@ void vtkChartXYZ::GetClippingPlaneEquation(int i, double *planeEquation) { int n = this->BoundingCube->GetNumberOfItems(); if (i >= 0 && i < n) - { + { // Get the plane vtkPlane *plane = this->BoundingCube->GetItem(i); double *normal = plane->GetNormal(); @@ -1652,5 +1652,5 @@ void vtkChartXYZ::GetClippingPlaneEquation(int i, double *planeEquation) planeEquation[3] = -(normal[0] * origin[0] + normal[1] * origin[1] + normal[2] * origin[2]); - } + } } diff --git a/Charts/Core/vtkColorLegend.cxx b/Charts/Core/vtkColorLegend.cxx index 5de234140eb..487b742d9a3 100644 --- a/Charts/Core/vtkColorLegend.cxx +++ b/Charts/Core/vtkColorLegend.cxx @@ -71,15 +71,15 @@ void vtkColorLegend::PrintSelf(ostream &os, vtkIndent indent) void vtkColorLegend::GetBounds(double bounds[4]) { if (this->TransferFunction) - { + { bounds[0] = this->TransferFunction->GetRange()[0]; bounds[1] = this->TransferFunction->GetRange()[1]; - } + } else - { + { bounds[0] = 0.0; bounds[1] = 1.0; - } + } bounds[2] = 0.0; bounds[3] = 1.0; } @@ -89,26 +89,26 @@ void vtkColorLegend::Update() { if (this->ImageData == 0 || this->ImageData->GetMTime() < this->GetMTime()) - { + { this->ComputeTexture(); - } + } // check if the range of our TransferFunction changed double bounds[4]; this->GetBounds(bounds); if (bounds[0] == bounds[1]) - { + { vtkWarningMacro(<< "The color transfer function seems to be empty."); this->Axis->Update(); return; - } + } double axisBounds[2]; this->Axis->GetUnscaledRange(axisBounds); if (bounds[0] != axisBounds[0] || bounds[1] != axisBounds[1]) - { + { this->Axis->SetUnscaledRange(bounds[0], bounds[1]); - } + } this->Axis->Update(); } @@ -117,20 +117,20 @@ void vtkColorLegend::Update() bool vtkColorLegend::Paint(vtkContext2D* painter) { if (this->TransferFunction == NULL) - { + { return true; - } + } this->GetBoundingRect(painter); if (this->DrawBorder) - { + { // Draw a box around the legend. painter->ApplyPen(this->Pen.GetPointer()); painter->ApplyBrush(this->Brush.GetPointer()); painter->DrawRect(this->Rect.GetX(), this->Rect.GetY(), this->Rect.GetWidth(), this->Rect.GetHeight()); - } + } painter->DrawImage(this->Position, this->ImageData); @@ -188,12 +188,12 @@ vtkRectf vtkColorLegend::GetBoundingRect(vtkContext2D *painter) if (this->CacheBounds && this->RectTime > this->GetMTime() && this->RectTime > this->PlotTime && this->RectTime > this->Axis->GetMTime()) - { + { return this->Rect; - } + } if (!this->CustomPositionSet) - { + { // if the Position ivar was not explicitly set, we compute the // location of the lower left point of the legend here. float posX = floor(this->Point[0]); @@ -202,7 +202,7 @@ vtkRectf vtkColorLegend::GetBoundingRect(vtkContext2D *painter) float posH = this->Position.GetHeight(); if (this->Orientation == vtkColorLegend::VERTICAL) - { + { // For vertical orientation, we need to move our anchor point // further to the left to accommodate the width of the axis. // To do this, we query our axis to get its preliminary bounds. @@ -212,49 +212,49 @@ vtkRectf vtkColorLegend::GetBoundingRect(vtkContext2D *painter) this->Axis->Update(); vtkRectf axisRect = this->Axis->GetBoundingRect(painter); posX -= axisRect.GetWidth(); - } + } // Compute bottom left point based on current alignment. if (this->HorizontalAlignment == vtkChartLegend::CENTER) - { + { posX -= posW / 2.0; - } + } else if (this->HorizontalAlignment == vtkChartLegend::RIGHT) - { + { posX -= posW; - } + } if (this->VerticalAlignment == vtkChartLegend::CENTER) - { + { posY -= posH / 2.0; - } + } else if (this->VerticalAlignment == vtkChartLegend::TOP) - { + { posY -= posH; - } + } this->Position.SetX(posX); this->Position.SetY(posY); this->UpdateAxisPosition(); - } + } this->Axis->Update(); vtkRectf axisRect = this->Axis->GetBoundingRect(painter); if (this->Orientation == vtkColorLegend::HORIZONTAL) - { + { // "+ 1" so the texture doesn't obscure the border this->Rect = vtkRectf(this->Position.GetX(), this->Position.GetY() - axisRect.GetHeight() + 1, this->Position.GetWidth() + 1, this->Position.GetHeight() + axisRect.GetHeight()); - } + } else - { + { this->Rect = vtkRectf(this->Position.GetX(), this->Position.GetY(), this->Position.GetWidth() + axisRect.GetWidth(), this->Position.GetHeight()); - } + } this->RectTime.Modified(); return this->Rect; @@ -265,21 +265,21 @@ vtkRectf vtkColorLegend::GetBoundingRect(vtkContext2D *painter) void vtkColorLegend::ComputeTexture() { if (this->TransferFunction == NULL) - { + { return; - } + } if (!this->ImageData) - { + { this->ImageData = vtkSmartPointer::New(); - } + } double bounds[4]; this->GetBounds(bounds); if (bounds[0] == bounds[1]) - { + { vtkWarningMacro(<< "The color transfer function seems to be empty."); return; - } + } // Set the axis up this->Axis->SetUnscaledRange(bounds[0], bounds[1]); @@ -290,23 +290,23 @@ void vtkColorLegend::ComputeTexture() double* values = new double[dimension]; // Texture 1D if (this->Orientation == vtkColorLegend::VERTICAL) - { + { this->ImageData->SetExtent(0, 0, 0, dimension-1, 0, 0); - } + } else - { + { this->ImageData->SetExtent(0, dimension-1, 0, 0, 0, 0); - } + } this->ImageData->AllocateScalars(VTK_UNSIGNED_CHAR, 3); for (int i = 0; i < dimension; ++i) - { + { values[i] = bounds[0] + i * (bounds[1] - bounds[0]) / (dimension - 1); - } + } unsigned char* ptr = reinterpret_cast(this->ImageData->GetScalarPointer()); this->TransferFunction->MapScalarsThroughTable2( @@ -337,15 +337,15 @@ void vtkColorLegend::ScalarsToColorsModified(vtkObject* vtkNotUsed(object), void vtkColorLegend::SetOrientation(int orientation) { if (orientation < 0 || orientation > 1) - { + { vtkErrorMacro("Error, invalid orientation value supplied: " << orientation) return; - } + } this->Orientation = orientation; if (this->Orientation == vtkColorLegend::HORIZONTAL) - { + { this->Axis->SetPosition(vtkAxis::BOTTOM); - } + } } //----------------------------------------------------------------------------- @@ -364,22 +364,22 @@ vtkStdString vtkColorLegend::GetTitle() void vtkColorLegend::UpdateAxisPosition() { if (this->Orientation == vtkColorLegend::VERTICAL) - { + { this->Axis->SetPoint1( vtkVector2f(this->Position.GetX() + this->Position.GetWidth(), this->Position.GetY())); this->Axis->SetPoint2( vtkVector2f(this->Position.GetX() + this->Position.GetWidth(), this->Position.GetY() + this->Position.GetHeight())); - } + } else - { + { this->Axis->SetPoint1( vtkVector2f(this->Position.GetX(), this->Position.GetY())); this->Axis->SetPoint2( vtkVector2f(this->Position.GetX() + this->Position.GetWidth(), this->Position.GetY())); - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkColorTransferControlPointsItem.cxx b/Charts/Core/vtkColorTransferControlPointsItem.cxx index b6e5f9733d5..4235e0003dd 100644 --- a/Charts/Core/vtkColorTransferControlPointsItem.cxx +++ b/Charts/Core/vtkColorTransferControlPointsItem.cxx @@ -45,11 +45,11 @@ vtkColorTransferControlPointsItem::vtkColorTransferControlPointsItem() vtkColorTransferControlPointsItem::~vtkColorTransferControlPointsItem() { if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->RemoveObserver(this->Callback); this->ColorTransferFunction->Delete(); this->ColorTransferFunction = 0; - } + } } //----------------------------------------------------------------------------- @@ -58,32 +58,32 @@ void vtkColorTransferControlPointsItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "ColorTransferFunction: "; if (this->ColorTransferFunction) - { + { os << endl; this->ColorTransferFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- void vtkColorTransferControlPointsItem::emitEvent(unsigned long event, void* params) { if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->InvokeEvent(event, params); - } + } } //----------------------------------------------------------------------------- vtkMTimeType vtkColorTransferControlPointsItem::GetControlPointsMTime() { if (this->ColorTransferFunction) - { + { return this->ColorTransferFunction->GetMTime(); - } + } return this->GetMTime(); } @@ -91,20 +91,20 @@ vtkMTimeType vtkColorTransferControlPointsItem::GetControlPointsMTime() void vtkColorTransferControlPointsItem::SetColorTransferFunction(vtkColorTransferFunction* t) { if (t == this->ColorTransferFunction) - { + { return; - } + } if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(ColorTransferFunction, vtkColorTransferFunction, t); if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->AddObserver(vtkCommand::StartEvent, this->Callback); this->ColorTransferFunction->AddObserver(vtkCommand::ModifiedEvent, this->Callback); this->ColorTransferFunction->AddObserver(vtkCommand::EndEvent, this->Callback); - } + } this->ResetBounds(); this->ComputePoints(); } @@ -114,11 +114,11 @@ void vtkColorTransferControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdTy { assert(index != -1); if (this->ColorFill) - { + { double xrgbms[6]; this->ColorTransferFunction->GetNodeValue(index, xrgbms); painter->GetBrush()->SetColorF(xrgbms[1], xrgbms[2], xrgbms[3], 0.55); - } + } this->vtkControlPointsItem::DrawPoint(painter, index); } @@ -137,13 +137,13 @@ void vtkColorTransferControlPointsItem::GetControlPoint(vtkIdType index, double* this->ColorTransferFunction); if (thisTF) - { + { thisTF->GetNodeValue(index, xrgbms); pos[0] = xrgbms[0]; pos[1] = 0.5; pos[2] = xrgbms[4]; pos[3] = xrgbms[5]; - } + } } //----------------------------------------------------------------------------- @@ -154,23 +154,23 @@ void vtkColorTransferControlPointsItem::SetControlPoint(vtkIdType index, double* if (newPos[0] != xrgbms[0] || newPos[2] != xrgbms[1] || newPos[3] != xrgbms[2]) - { + { xrgbms[0] = newPos[0]; xrgbms[4] = newPos[2]; xrgbms[5] = newPos[3]; this->StartChanges(); this->ColorTransferFunction->SetNodeValue(index, xrgbms); this->EndChanges(); - } + } } //----------------------------------------------------------------------------- void vtkColorTransferControlPointsItem::EditPoint(float tX, float tY) { if (!this->ColorTransferFunction) - { + { return; - } + } this->StartChanges(); @@ -180,12 +180,12 @@ void vtkColorTransferControlPointsItem::EditPoint(float tX, float tY) xrgbms[5] += tY; this->ColorTransferFunction->SetNodeValue(this->CurrentPoint, xrgbms); if (this->CurrentPoint > 0) - { + { this->ColorTransferFunction->GetNodeValue(this->CurrentPoint - 1, xrgbms); xrgbms[4] += tX; xrgbms[5] += tY; this->ColorTransferFunction->SetNodeValue(this->CurrentPoint - 1, xrgbms); - } + } this->EndChanges(); } @@ -194,9 +194,9 @@ void vtkColorTransferControlPointsItem::EditPoint(float tX, float tY) vtkIdType vtkColorTransferControlPointsItem::AddPoint(double* newPos) { if (!this->ColorTransferFunction) - { + { return -1; - } + } this->StartChanges(); @@ -216,9 +216,9 @@ vtkIdType vtkColorTransferControlPointsItem::RemovePoint(double* currentPoint) { if (!this->ColorTransferFunction || !this->IsPointRemovable( this->GetControlPointId(currentPoint))) - { + { return -1; - } + } this->StartChanges(); @@ -238,17 +238,17 @@ vtkIdType vtkColorTransferControlPointsItem::RemovePoint(double* currentPoint) void vtkColorTransferControlPointsItem::ComputeBounds(double* bounds) { if (this->ColorTransferFunction) - { + { const double* range = this->ColorTransferFunction->GetRange(); bounds[0] = range[0]; bounds[1] = range[1]; bounds[2] = 0.5; bounds[3] = 0.5; - } + } else - { + { this->Superclass::ComputeBounds(bounds); - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkColorTransferFunctionItem.cxx b/Charts/Core/vtkColorTransferFunctionItem.cxx index b6036a23b1e..b4c55f128ea 100644 --- a/Charts/Core/vtkColorTransferFunctionItem.cxx +++ b/Charts/Core/vtkColorTransferFunctionItem.cxx @@ -39,11 +39,11 @@ vtkColorTransferFunctionItem::vtkColorTransferFunctionItem() vtkColorTransferFunctionItem::~vtkColorTransferFunctionItem() { if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->RemoveObserver(this->Callback); this->ColorTransferFunction->Delete(); this->ColorTransferFunction = 0; - } + } } //----------------------------------------------------------------------------- @@ -52,14 +52,14 @@ void vtkColorTransferFunctionItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "ColorTransferFunction: "; if (this->ColorTransferFunction) - { + { os << endl; this->ColorTransferFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- @@ -67,29 +67,29 @@ void vtkColorTransferFunctionItem::ComputeBounds(double* bounds) { this->Superclass::ComputeBounds(bounds); if (this->ColorTransferFunction) - { + { double* range = this->ColorTransferFunction->GetRange(); bounds[0] = range[0]; bounds[1] = range[1]; - } + } } //----------------------------------------------------------------------------- void vtkColorTransferFunctionItem::SetColorTransferFunction(vtkColorTransferFunction* t) { if (t == this->ColorTransferFunction) - { + { return; - } + } if (this->ColorTransferFunction) - { + { this->ColorTransferFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(ColorTransferFunction, vtkColorTransferFunction, t); if (t) - { + { t->AddObserver(vtkCommand::ModifiedEvent, this->Callback); - } + } this->ScalarsToColorsModified(t, vtkCommand::ModifiedEvent, 0); } @@ -100,13 +100,13 @@ void vtkColorTransferFunctionItem::ComputeTexture() this->GetBounds(bounds); if (bounds[0] == bounds[1] || !this->ColorTransferFunction) - { + { return; - } + } if (this->Texture == 0) - { + { this->Texture = vtkImageData::New(); - } + } // Could depend of the screen resolution const int dimension = this->GetTextureWidth(); @@ -121,30 +121,30 @@ void vtkColorTransferFunctionItem::ComputeTexture() double logBoundsDelta = (bounds[0] > 0.0 && bounds[1] > 0.0)? (log10(bounds[1])-log10(bounds[0])) : 0.0; for (int i = 0; i < dimension; ++i) - { + { if (isLogTable) - { + { double normVal = i/(dimension-1.0); double lval = logBoundsMin + normVal*logBoundsDelta; values[i] = pow(10.0, lval); - } + } else - { + { values[i] = bounds[0] + i * (bounds[1] - bounds[0]) / (dimension - 1); - } } + } unsigned char* ptr = reinterpret_cast(this->Texture->GetScalarPointer(0,0,0)); this->ColorTransferFunction->MapScalarsThroughTable2( values, ptr, VTK_DOUBLE, dimension, VTK_LUMINANCE, VTK_RGBA); if (this->Opacity != 1.0) - { + { for (int i = 0; i < dimension; ++i) - { + { ptr[3] = static_cast(this->Opacity * ptr[3]); ptr+=4; - } } + } delete [] values; return; } diff --git a/Charts/Core/vtkCompositeControlPointsItem.cxx b/Charts/Core/vtkCompositeControlPointsItem.cxx index 2deafba7109..3b37ac5c669 100644 --- a/Charts/Core/vtkCompositeControlPointsItem.cxx +++ b/Charts/Core/vtkCompositeControlPointsItem.cxx @@ -50,16 +50,16 @@ vtkCompositeControlPointsItem::vtkCompositeControlPointsItem() vtkCompositeControlPointsItem::~vtkCompositeControlPointsItem() { if (this->OpacityFunction) - { + { this->OpacityFunction->RemoveObserver(this->Callback); this->OpacityFunction->Delete(); this->OpacityFunction = 0; - } + } if (this->OpacityPointHandle) - { + { this->OpacityPointHandle->Delete(); this->OpacityPointHandle = 0; - } + } } //----------------------------------------------------------------------------- @@ -68,24 +68,24 @@ void vtkCompositeControlPointsItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "OpacityFunction: "; if (this->OpacityFunction) - { + { os << endl; this->OpacityFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } os << indent << "OpacityFunction: "; if (this->OpacityPointHandle) - { + { os << endl; this->OpacityPointHandle->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } os << indent << "UseOpacityPointHandles: " << this->UseOpacityPointHandles << endl; } @@ -93,9 +93,9 @@ void vtkCompositeControlPointsItem::PrintSelf(ostream &os, vtkIndent indent) void vtkCompositeControlPointsItem::emitEvent(unsigned long event, void* params) { if (this->OpacityFunction) - { + { this->OpacityFunction->InvokeEvent(event, params); - } + } this->Superclass::emitEvent(event, params); } @@ -104,9 +104,9 @@ vtkMTimeType vtkCompositeControlPointsItem::GetControlPointsMTime() { vtkMTimeType mTime = this->Superclass::GetControlPointsMTime(); if (this->OpacityFunction) - { + { mTime = std::max(mTime, this->OpacityFunction->GetMTime()); - } + } return mTime; } @@ -114,24 +114,24 @@ vtkMTimeType vtkCompositeControlPointsItem::GetControlPointsMTime() void vtkCompositeControlPointsItem::SetOpacityFunction(vtkPiecewiseFunction* function) { if (function == this->OpacityFunction) - { + { return; - } + } if (this->OpacityFunction) - { + { this->OpacityFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(OpacityFunction, vtkPiecewiseFunction, function); if (this->PointsFunction == ColorAndOpacityPointsFunction) - { + { this->SilentMergeTransferFunctions(); - } + } if (this->OpacityFunction) - { + { this->OpacityFunction->AddObserver(vtkCommand::StartEvent, this->Callback); this->OpacityFunction->AddObserver(vtkCommand::ModifiedEvent, this->Callback); this->OpacityFunction->AddObserver(vtkCommand::EndEvent, this->Callback); - } + } this->ResetBounds(); this->ComputePoints(); } @@ -140,17 +140,17 @@ void vtkCompositeControlPointsItem::SetOpacityFunction(vtkPiecewiseFunction* fun void vtkCompositeControlPointsItem::SetColorTransferFunction(vtkColorTransferFunction* c) { if (c == this->ColorTransferFunction) - { + { return; - } + } // We need to set the color transfer function here (before // Superclass::SetPiecewiseFunction) to be able to have a valid // color transfer function for MergeColorTransferFunction(). vtkSetObjectBodyMacro(ColorTransferFunction, vtkColorTransferFunction, c); if (this->PointsFunction == ColorAndOpacityPointsFunction) - { + { this->SilentMergeTransferFunctions(); - } + } this->Superclass::SetColorTransferFunction(c); } @@ -167,19 +167,19 @@ void vtkCompositeControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType i { if (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction) - { + { this->Superclass::DrawPoint(painter, index); return; - } + } if (this->PointsFunction == OpacityPointsFunction && this->ColorFill && this->ColorTransferFunction) - { + { double xvms[4]; this->OpacityFunction->GetNodeValue(index, xvms); unsigned char* rgb = this->ColorTransferFunction->MapValue(xvms[0]); painter->GetBrush()->SetColorF( rgb[0] / 255., rgb[1] / 255., rgb[2] / 255., 0.55); - } + } this->vtkControlPointsItem::DrawPoint(painter, index); } @@ -189,15 +189,15 @@ vtkIdType vtkCompositeControlPointsItem::GetNumberOfPoints()const if (this->ColorTransferFunction && (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { return this->Superclass::GetNumberOfPoints(); - } + } if (this->OpacityFunction && (this->PointsFunction == OpacityPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { return static_cast(this->OpacityFunction->GetSize()); - } + } return 0; } @@ -206,17 +206,17 @@ void vtkCompositeControlPointsItem::SetControlPoint(vtkIdType index, double* new { if (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction) - { + { this->Superclass::SetControlPoint(index, newPos); - } + } if (this->OpacityFunction && (this->PointsFunction == OpacityPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { this->StartChanges(); this->OpacityFunction->SetNodeValue(index, newPos); this->EndChanges(); - } + } } //----------------------------------------------------------------------------- @@ -224,15 +224,15 @@ void vtkCompositeControlPointsItem::GetControlPoint(vtkIdType index, double* pos { if (!this->OpacityFunction || this->PointsFunction == ColorPointsFunction) - { + { this->Superclass::GetControlPoint(index, pos); if (this->OpacityFunction) - { + { pos[1] = const_cast(this->OpacityFunction) ->GetValue(pos[0]); - } - return; } + return; + } const_cast(this->OpacityFunction) ->GetNodeValue(index, pos); } @@ -242,13 +242,13 @@ void vtkCompositeControlPointsItem::EditPoint(float tX, float tY) { if (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction) - { + { this->Superclass::EditPoint(tX, tY); - } + } if (this->OpacityFunction && (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { this->StartChanges(); double xvms[4]; this->OpacityFunction->GetNodeValue(this->CurrentPoint, xvms); @@ -257,14 +257,14 @@ void vtkCompositeControlPointsItem::EditPoint(float tX, float tY) this->OpacityFunction->SetNodeValue(this->CurrentPoint, xvms); // Not sure why we move the point before too if (this->CurrentPoint > 0) - { + { this->OpacityFunction->GetNodeValue(this->CurrentPoint - 1, xvms); xvms[2] += tX; xvms[3] += tY; this->OpacityFunction->SetNodeValue(this->CurrentPoint - 1, xvms); - } - this->EndChanges(); } + this->EndChanges(); + } } //----------------------------------------------------------------------------- @@ -275,18 +275,18 @@ vtkIdType vtkCompositeControlPointsItem::AddPoint(double* newPos) if (this->OpacityFunction && (this->PointsFunction == OpacityPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { addedPoint = this->OpacityFunction->AddPoint(newPos[0], newPos[1]); if (this->PointsFunction == OpacityPointsFunction) - { + { this->vtkControlPointsItem::AddPointId(addedPoint); - } } + } if (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction) - { + { addedPoint = this->Superclass::AddPoint(newPos); - } + } this->EndChanges(); return addedPoint; } @@ -296,22 +296,22 @@ vtkIdType vtkCompositeControlPointsItem::RemovePoint(double* currentPoint) { vtkIdType removedPoint = -1; if (!this->IsPointRemovable(this->GetControlPointId(currentPoint))) - { + { return removedPoint; - } + } this->StartChanges(); if (this->PointsFunction == ColorPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction) - { + { removedPoint = this->Superclass::RemovePoint(currentPoint); - } + } if (this->OpacityFunction && (this->PointsFunction == OpacityPointsFunction || this->PointsFunction == ColorAndOpacityPointsFunction)) - { + { removedPoint = this->OpacityFunction->RemovePoint(currentPoint[0]); - } + } this->EndChanges(); return removedPoint; } @@ -320,14 +320,14 @@ vtkIdType vtkCompositeControlPointsItem::RemovePoint(double* currentPoint) void vtkCompositeControlPointsItem::MergeTransferFunctions() { if (!this->ColorTransferFunction || !this->OpacityFunction) - { + { return; - } + } // Naive implementation that does the work but can be a bit slow // Copy OpacityFunction points into the ColorTransferFunction const int piecewiseFunctionCount = this->OpacityFunction->GetSize(); for (int i = 0; i < piecewiseFunctionCount; ++i) - { + { double piecewisePoint[4]; this->OpacityFunction->GetNodeValue(i, piecewisePoint); double rgb[3]; @@ -335,18 +335,18 @@ void vtkCompositeControlPointsItem::MergeTransferFunctions() // note that we might lose the midpoint/sharpness of the point if any this->ColorTransferFunction->RemovePoint(piecewisePoint[0]); this->ColorTransferFunction->AddRGBPoint(piecewisePoint[0], rgb[0], rgb[1], rgb[2], piecewisePoint[2], piecewisePoint[3]); - } + } // Copy ColorTransferFunction points into the OpacityFunction const int colorFunctionCount = this->ColorTransferFunction->GetSize(); for (int i = 0; i < colorFunctionCount; ++i) - { + { double xrgbms[6]; this->ColorTransferFunction->GetNodeValue(i, xrgbms); double value = this->OpacityFunction->GetValue(xrgbms[0]); // note that we might lose the midpoint/sharpness of the point if any this->OpacityFunction->RemovePoint(xrgbms[0]); this->OpacityFunction->AddPoint(xrgbms[0], value, xrgbms[4], xrgbms[5]); - } + } } //----------------------------------------------------------------------------- @@ -362,20 +362,20 @@ bool vtkCompositeControlPointsItem::MouseButtonPressEvent(const vtkContextMouseE { bool result=false; if(this->OpacityPointHandle && this->OpacityPointHandle->GetVisible()) - { + { result = this->OpacityPointHandle->MouseButtonPressEvent(mouse); - } + } if(!result) - { + { result = this->Superclass::MouseButtonPressEvent(mouse); if(result && this->OpacityPointHandle && this->OpacityPointHandle->GetVisible() && this->OpacityPointHandle->GetCurrentPointIndex() != this->GetCurrentPoint()) - { + { this->OpacityPointHandle->SetVisible(false); - } } + } return result; } @@ -384,10 +384,10 @@ bool vtkCompositeControlPointsItem::MouseDoubleClickEvent(const vtkContextMouseE { bool superRes = this->Superclass::MouseDoubleClickEvent(mouse); if(superRes) - { + { vtkIdType curIdx = this->GetCurrentPoint(); this->EditPointCurve(curIdx); - } + } return superRes; } @@ -396,13 +396,13 @@ bool vtkCompositeControlPointsItem::MouseMoveEvent(const vtkContextMouseEvent &m { bool result=false; if(this->OpacityPointHandle && this->OpacityPointHandle->GetVisible()) - { + { result = this->OpacityPointHandle->MouseMoveEvent(mouse); - } + } if(!result) - { + { result = this->Superclass::MouseMoveEvent(mouse); - } + } return result; } @@ -410,23 +410,23 @@ bool vtkCompositeControlPointsItem::MouseMoveEvent(const vtkContextMouseEvent &m void vtkCompositeControlPointsItem::EditPointCurve(vtkIdType index) { if(index<0 || index>=this->GetNumberOfPoints()) - { + { return; - } + } if(this->GetUseOpacityPointHandles()) - { + { if(!this->OpacityPointHandle) - { + { this->OpacityPointHandle = vtkPiecewisePointHandleItem::New(); this->AddItem(this->OpacityPointHandle); this->OpacityPointHandle->SetPiecewiseFunction( this->GetOpacityFunction()); - } + } else - { + { this->OpacityPointHandle->SetVisible( !this->OpacityPointHandle->GetVisible()); this->GetScene()->SetDirty(true); - } } + } } diff --git a/Charts/Core/vtkCompositeTransferFunctionItem.cxx b/Charts/Core/vtkCompositeTransferFunctionItem.cxx index e96b9361ced..661b59e638d 100644 --- a/Charts/Core/vtkCompositeTransferFunctionItem.cxx +++ b/Charts/Core/vtkCompositeTransferFunctionItem.cxx @@ -42,11 +42,11 @@ vtkCompositeTransferFunctionItem::vtkCompositeTransferFunctionItem() vtkCompositeTransferFunctionItem::~vtkCompositeTransferFunctionItem() { if (this->OpacityFunction) - { + { this->OpacityFunction->RemoveObserver(this->Callback); this->OpacityFunction->Delete(); this->OpacityFunction = 0; - } + } } //----------------------------------------------------------------------------- @@ -55,14 +55,14 @@ void vtkCompositeTransferFunctionItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "CompositeTransferFunction: "; if (this->OpacityFunction) - { + { os << endl; this->OpacityFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- @@ -70,29 +70,29 @@ void vtkCompositeTransferFunctionItem::ComputeBounds(double* bounds) { this->Superclass::ComputeBounds(bounds); if (this->OpacityFunction) - { + { double* opacityRange = this->OpacityFunction->GetRange(); bounds[0] = std::min(bounds[0], opacityRange[0]); bounds[1] = std::max(bounds[1], opacityRange[1]); - } + } } //----------------------------------------------------------------------------- void vtkCompositeTransferFunctionItem::SetOpacityFunction(vtkPiecewiseFunction* opacity) { if (opacity == this->OpacityFunction) - { + { return; - } + } if (this->OpacityFunction) - { + { this->OpacityFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(OpacityFunction, vtkPiecewiseFunction, opacity); if (opacity) - { + { opacity->AddObserver(vtkCommand::ModifiedEvent, this->Callback); - } + } this->ScalarsToColorsModified(this->OpacityFunction, vtkCommand::ModifiedEvent, 0); } @@ -104,13 +104,13 @@ void vtkCompositeTransferFunctionItem::ComputeTexture() this->GetBounds(bounds); if (bounds[0] == bounds[1] || !this->OpacityFunction) - { + { return; - } + } if (this->Texture == 0) - { + { this->Texture = vtkImageData::New(); - } + } const int dimension = this->GetTextureWidth(); double* values = new double[dimension]; @@ -119,30 +119,30 @@ void vtkCompositeTransferFunctionItem::ComputeTexture() reinterpret_cast(this->Texture->GetScalarPointer(0,0,0)); // TBD: maybe the shape should be defined somewhere else... if (this->MaskAboveCurve || this->PolyLinePen->GetLineType() != vtkPen::SOLID_LINE) - { + { this->Shape->SetNumberOfPoints(dimension); double step = (bounds[1] - bounds[0]) / dimension; for (int i = 0; i < dimension; ++i) - { + { ptr[3] = static_cast(values[i] * this->Opacity * 255); if (values[i] < 0. || values[i] > 1.) - { + { vtkWarningMacro( << "Opacity at point " << i << " is " << values[i] << " which is outside the valid range of [0,1]"); - } + } this->Shape->SetPoint(i, bounds[0] + step * i, values[i]); ptr+=4; - } } + } else - { + { for (int i = 0; i < dimension; ++i) - { + { ptr[3] = static_cast(values[i] * this->Opacity * 255); assert(values[i] <= 1. && values[i] >= 0.); ptr+=4; - } } + } delete [] values; return; } diff --git a/Charts/Core/vtkContextArea.cxx b/Charts/Core/vtkContextArea.cxx index b332d938394..3b59e05a582 100644 --- a/Charts/Core/vtkContextArea.cxx +++ b/Charts/Core/vtkContextArea.cxx @@ -50,9 +50,9 @@ vtkContextArea::vtkContextArea() this->Axes[vtkAxis::RIGHT]->SetPosition(vtkAxis::RIGHT); for (int i = 0; i < 4; ++i) - { + { this->AddItem(this->Axes[i]); - } + } this->AddItem(this->Clip.GetPointer()); this->Clip->AddItem(this->Transform.GetPointer()); @@ -94,16 +94,16 @@ void vtkContextArea::LayoutAxes(vtkContext2D *painter) // Regenerate ticks, labels, etc: for (int i = 0; i < 4; ++i) - { + { this->Axes[i]->Update(); - } + } } //------------------------------------------------------------------------------ vtkRecti vtkContextArea::ComputeDrawAreaGeometry(vtkContext2D *p) { switch (this->DrawAreaResizeBehavior) - { + { case vtkContextArea::DARB_Expand: return this->ComputeExpandedDrawAreaGeometry(p); case vtkContextArea::DARB_FixedAspect: @@ -116,7 +116,7 @@ vtkRecti vtkContextArea::ComputeDrawAreaGeometry(vtkContext2D *p) vtkErrorMacro("Invalid resize behavior enum value: " << this->DrawAreaResizeBehavior); break; - } + } return vtkRecti(); } @@ -131,7 +131,7 @@ vtkRecti vtkContextArea::ComputeExpandedDrawAreaGeometry(vtkContext2D *painter) vtkRecti draw(this->DrawAreaGeometry); // Start with last attempt vtkRecti lastDraw; for (int pass = 0; pass < 3; ++pass) - { + { // Set axes locations to the current draw rect: this->TopAxis->SetPoint1(draw.GetTopLeft().Cast()); this->TopAxis->SetPoint2(draw.GetTopRight().Cast()); @@ -146,11 +146,11 @@ vtkRecti vtkContextArea::ComputeExpandedDrawAreaGeometry(vtkContext2D *painter) vtkVector2i bottomLeft = draw.GetBottomLeft(); vtkVector2i topRight = draw.GetTopRight(); for (int i = 0; i < 4; ++i) - { + { this->Axes[i]->Update(); vtkRectf bounds = this->Axes[i]->GetBoundingRect(painter); switch (static_cast(i)) - { + { case vtkAxis::LEFT: bottomLeft.SetX(geo.GetLeft() + static_cast(bounds.GetWidth())); @@ -169,8 +169,8 @@ vtkRecti vtkContextArea::ComputeExpandedDrawAreaGeometry(vtkContext2D *painter) break; default: abort(); // Shouldn't happen unless vtkAxis::Location is changed. - } } + } // Update draw geometry: lastDraw = draw; @@ -178,10 +178,10 @@ vtkRecti vtkContextArea::ComputeExpandedDrawAreaGeometry(vtkContext2D *painter) topRight.GetX() - bottomLeft.GetX(), topRight.GetY() - bottomLeft.GetY()); if (draw == lastDraw) - { + { break; // converged - } } + } return draw; } @@ -193,21 +193,21 @@ vtkRecti vtkContextArea::ComputeFixedAspectDrawAreaGeometry(vtkContext2D *p) float aspect = draw.GetWidth() / static_cast(draw.GetHeight()); if (aspect > this->FixedAspect) // Too wide: - { + { int targetWidth = vtkContext2D::FloatToInt( this->FixedAspect * draw.GetHeight()); int delta = draw.GetWidth() - targetWidth; draw.SetX(draw.GetX() + (delta/2)); draw.SetWidth(targetWidth); - } + } else if (aspect < this->FixedAspect) // Too tall: - { + { int targetHeight = vtkContext2D::FloatToInt( draw.GetWidth() / this->FixedAspect); int delta = draw.GetHeight() - targetHeight; draw.SetY(draw.GetY() + (delta/2)); draw.SetHeight(targetHeight); - } + } return draw; } @@ -271,7 +271,7 @@ void vtkContextArea::PrintSelf(std::ostream &os, vtkIndent indent) vtkContextAreaPrintMemberPOD(DrawAreaGeometry); os << indent << "DrawAreaResizeBehavior: "; switch (this->DrawAreaResizeBehavior) - { + { case vtkContextArea::DARB_Expand: os << "DARB_Expand\n"; break; @@ -287,7 +287,7 @@ void vtkContextArea::PrintSelf(std::ostream &os, vtkIndent indent) default: os << "(Invalid enum value: " << this->DrawAreaResizeBehavior << ")\n"; break; - } + } vtkContextAreaPrintMemberPOD(FixedAspect); vtkContextAreaPrintMemberPOD(FixedRect); vtkContextAreaPrintMemberPOD(FixedMargins); @@ -313,10 +313,10 @@ vtkAbstractContextItem *vtkContextArea::GetDrawAreaItem() bool vtkContextArea::Paint(vtkContext2D *painter) { if (this->FillViewport) - { + { vtkVector2i vpSize = painter->GetDevice()->GetViewportSize(); this->SetGeometry(vtkRecti(0, 0, vpSize[0], vpSize[1])); - } + } this->LayoutAxes(painter); this->UpdateDrawArea(); @@ -328,10 +328,10 @@ void vtkContextArea::SetFixedAspect(float aspect) { this->SetDrawAreaResizeBehavior(DARB_FixedAspect); if (this->FixedAspect != aspect) - { + { this->FixedAspect = aspect; this->Modified(); - } + } } //------------------------------------------------------------------------------ @@ -339,10 +339,10 @@ void vtkContextArea::SetFixedRect(vtkRecti rect) { this->SetDrawAreaResizeBehavior(DARB_FixedRect); if (this->FixedRect != rect) - { + { this->FixedRect = rect; this->Modified(); - } + } } //------------------------------------------------------------------------------ @@ -369,10 +369,10 @@ void vtkContextArea::SetFixedMargins(vtkContextArea::Margins margins) { this->SetDrawAreaResizeBehavior(DARB_FixedMargins); if (margins != this->FixedMargins) - { + { this->FixedMargins = margins; this->Modified(); - } + } } //------------------------------------------------------------------------------ diff --git a/Charts/Core/vtkContextPolygon.cxx b/Charts/Core/vtkContextPolygon.cxx index e6150f55e19..3cb49f39304 100644 --- a/Charts/Core/vtkContextPolygon.cxx +++ b/Charts/Core/vtkContextPolygon.cxx @@ -87,25 +87,25 @@ bool vtkContextPolygon::Contains(const vtkVector2f &point) const bool inside = false; float xintersection; for(size_t i = 0; i < d->points.size(); i++) - { + { const vtkVector2f &p1 = d->points[i]; const vtkVector2f &p2 = d->points[(i+1) % d->points.size()]; if (y > std::min(p1.GetY(), p2.GetY()) && y <= std::max(p1.GetY(),p2.GetY()) && p1.GetY() != p2.GetY()) - { + { if (x <= std::max(p1.GetX(), p2.GetX()) ) - { + { xintersection = (y - p1.GetY())*(p2.GetX() - p1.GetX())/(p2.GetY() - p1.GetY()) + p1.GetX(); if ( p1.GetX() == p2.GetX() || x <= xintersection) - { + { // each time we intersect we switch if we are in side or not inside = !inside; - } } } } + } return inside; } @@ -125,9 +125,9 @@ vtkContextPolygon vtkContextPolygon::Transformed(vtkTransform2D *transform) cons vtkContextPolygon& vtkContextPolygon::operator=(const vtkContextPolygon &other) { if(this != &other) - { + { d->points = other.d->points; - } + } return *this; } diff --git a/Charts/Core/vtkControlPointsItem.cxx b/Charts/Core/vtkControlPointsItem.cxx index cbec871ea68..e53d78678f5 100644 --- a/Charts/Core/vtkControlPointsItem.cxx +++ b/Charts/Core/vtkControlPointsItem.cxx @@ -96,25 +96,25 @@ vtkControlPointsItem::~vtkControlPointsItem() { this->SetLabelFormat(NULL); if (this->Callback) - { + { this->Callback->Delete(); this->Callback = 0; - } + } if (this->SelectedPointPen) - { + { this->SelectedPointPen->Delete(); this->SelectedPointPen = 0; - } + } if (this->SelectedPointBrush) - { + { this->SelectedPointBrush->Delete(); this->SelectedPointBrush = 0; - } + } if (this->Transform) - { + { this->Transform->Delete(); this->Transform = 0; - } + } } //----------------------------------------------------------------------------- @@ -134,19 +134,19 @@ void vtkControlPointsItem::GetBounds(double bounds[4]) // valid user bounds ? use them if (this->UserBounds[0] <= this->UserBounds[1] && this->UserBounds[2] <= this->UserBounds[3]) - { + { bounds[0] = this->UserBounds[0]; bounds[1] = this->UserBounds[1]; bounds[2] = this->UserBounds[2]; bounds[3] = this->UserBounds[3]; return; - } + } // invalid bounds ? compute them if (!(this->Bounds[0] <= this->Bounds[1] && this->Bounds[2] > this->Bounds[3])) - { + { this->ComputeBounds(); - } + } bounds[0] = this->Bounds[0]; bounds[1] = this->Bounds[1]; bounds[2] = this->Bounds[2]; @@ -177,9 +177,9 @@ void vtkControlPointsItem::ComputeBounds() this->Bounds[1] != oldBounds[1] || this->Bounds[2] != oldBounds[2] || this->Bounds[3] != oldBounds[3]) - { + { this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -188,14 +188,14 @@ void vtkControlPointsItem::ComputeBounds( double* bounds) bounds[0] = bounds[2] = VTK_DOUBLE_MAX; bounds[1] = bounds[3] = -VTK_DOUBLE_MAX; for (vtkIdType i=0; i < this->GetNumberOfPoints(); ++i) - { + { double point[4]; this->GetControlPoint(i, point); bounds[0] = std::min(bounds[0], point[0]); bounds[1] = std::max(bounds[1], point[0]); bounds[2] = std::min(bounds[2], point[1]); bounds[3] = std::max(bounds[3], point[1]); - } + } } //----------------------------------------------------------------------------- @@ -216,11 +216,11 @@ bool vtkControlPointsItem::Paint(vtkContext2D* painter) this->InvertShadow = true; float oldScreenPointRadius = this->ScreenPointRadius; if (this->Selection && this->Selection->GetNumberOfTuples()) - { + { //painter->GetPen()->SetWidth(oldPenWidth * 1.4); //this->ScreenPointRadius = oldScreenPointRadius * 1.1; this->DrawSelectedPoints(painter); - } + } this->ScreenPointRadius = oldScreenPointRadius; this->Transform->SetMatrix(painter->GetTransform()->GetMatrix()); @@ -234,10 +234,10 @@ void vtkControlPointsItem::StartChanges() { ++this->StartedChanges; if (this->StartedChanges == 1) - { + { this->InvokeEvent(vtkCommand::StartEvent); this->emitEvent(vtkCommand::StartEvent); - } + } } //----------------------------------------------------------------------------- @@ -246,10 +246,10 @@ void vtkControlPointsItem::EndChanges() --this->StartedChanges; assert(this->StartedChanges >=0); if (this->StartedChanges == 0) - { + { this->emitEvent(vtkCommand::EndEvent); this->InvokeEvent(vtkCommand::EndEvent); - } + } } //----------------------------------------------------------------------------- @@ -263,9 +263,9 @@ void vtkControlPointsItem::StartInteraction() void vtkControlPointsItem::StartInteractionIfNotStarted() { if (this->GetInteractionsCount() == 0) - { + { this->StartInteraction(); - } + } } //----------------------------------------------------------------------------- @@ -300,58 +300,58 @@ void vtkControlPointsItem::CallComputePoints( vtkControlPointsItem* item = reinterpret_cast(receiver); switch(event) - { + { case vtkCommand::StartEvent: ++item->BlockUpdates; break; case vtkCommand::EndEvent: --item->BlockUpdates; if (item->BlockUpdates == 0) - { + { item->ComputePoints(); - } + } break; case vtkCommand::ModifiedEvent: item->ComputePoints(); break; default: break; - } + } } //----------------------------------------------------------------------------- void vtkControlPointsItem::ComputePoints() { if (this->BlockUpdates > 0) - { + { return; - } + } if (this->Selection && this->GetNumberOfPoints() == 0) - { + { this->Selection->SetNumberOfTuples(0); - } + } const int selectedPointCount = this->Selection ? this->Selection->GetNumberOfTuples() : 0; if (selectedPointCount) - { + { vtkIdTypeArray* oldSelection = this->Selection; this->Selection = vtkIdTypeArray::New(); for (vtkIdType i = 0; i < selectedPointCount; ++i) - { + { if (oldSelection->GetValue(i) < this->GetNumberOfPoints()) - { + { this->SelectPoint(oldSelection->GetValue(i)); - } } - oldSelection->Delete(); } + oldSelection->Delete(); + } if (this->GetScene()) - { + { this->GetScene()->SetDirty(true); - } + } this->Modified(); } @@ -366,7 +366,7 @@ void vtkControlPointsItem::TransformScreenToData(const vtkVector2f& in, vtkVecto out.SetY(static_cast((out.GetY() / ss[3]) - ss[1])); if (this->UsingLogScale()) - { + { // using log scale. double bounds[4]; this->ComputeBounds(bounds); @@ -376,7 +376,7 @@ void vtkControlPointsItem::TransformScreenToData(const vtkVector2f& in, vtkVecto double lval = log10(bounds[0]) + normVal*(log10(bounds[1]) - log10(bounds[0])); posX = pow(10.0, lval); out.SetX(posX); - } + } } //----------------------------------------------------------------------------- @@ -384,7 +384,7 @@ void vtkControlPointsItem::TransformDataToScreen(const vtkVector2f& in, vtkVecto { out = in; if (this->UsingLogScale()) - { + { double bounds[4]; this->ComputeBounds(bounds); @@ -393,7 +393,7 @@ void vtkControlPointsItem::TransformDataToScreen(const vtkVector2f& in, vtkVecto (log10(bounds[1]) - log10(bounds[0])); posX = bounds[0] + lnormVal * (bounds[1] - bounds[0]); out.SetX(posX); - } + } // now, shift/scale to screen space. const vtkRectd& ss = this->ShiftScale; @@ -413,20 +413,20 @@ bool vtkControlPointsItem::Hit(const vtkContextMouseEvent &mouse) this->GetBounds(bounds); bool clamped = this->ClampPos(pos, bounds); if (!clamped) - { + { return true; - } + } // maybe the cursor is over the first or last point (which could be outside // the bounds because of the screen point size). pos[0] = vpos.GetX(); pos[1] = vpos.GetY(); for (int i = 0; i < this->GetNumberOfPoints(); ++i) - { + { if (this->IsOverPoint(pos, i)) - { + { return true; - } } + } return false; } @@ -434,31 +434,31 @@ bool vtkControlPointsItem::Hit(const vtkContextMouseEvent &mouse) bool vtkControlPointsItem::ClampPos(double pos[2], double bounds[4]) { if (bounds[1] < bounds[0] || bounds[3] < bounds[2]) - { + { // bounds are not valid. Don't clamp. return false; - } + } bool clamped = false; if (pos[0] < bounds[0]) - { + { pos[0] = bounds[0]; clamped = true; - } + } if (pos[0] > bounds[1]) - { + { pos[0] = bounds[1]; clamped = true; - } + } if (pos[1] < 0.) - { + { pos[1] = 0.; clamped = true; - } + } if (pos[1] > 1.) - { + { pos[1] = 1.; clamped = true; - } + } return clamped; } @@ -469,11 +469,11 @@ bool vtkControlPointsItem::ClampValidPos(double pos[2]) this->GetValidBounds(validBounds); if (validBounds[0] > this->ValidBounds[1] || validBounds[2] > this->ValidBounds[3]) - { + { double bounds[4]; this->GetBounds(bounds); return this->ClampPos(pos, bounds); - } + } return this->ClampPos(pos, validBounds); } @@ -482,14 +482,14 @@ void vtkControlPointsItem::DrawUnselectedPoints(vtkContext2D* painter) { const int count = this->GetNumberOfPoints(); for (vtkIdType i = 0; i < count; ++i) - { + { vtkIdType idx = this->Selection ? this->Selection->LookupValue(i) : -1; if (idx != -1) - { + { continue; - } - this->DrawPoint(painter, i); } + this->DrawPoint(painter, i); + } } //----------------------------------------------------------------------------- @@ -497,11 +497,11 @@ void vtkControlPointsItem::DrawSelectedPoints(vtkContext2D* painter) { const int count = this->Selection ? this->Selection->GetNumberOfTuples() : 0; for (vtkIdType i = 0; i < count; ++i) - { + { vtkIdType index = this->Selection->GetValue(i); assert(index != -1); this->DrawPoint(painter, index); - } + } } //----------------------------------------------------------------------------- @@ -538,23 +538,23 @@ void vtkControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType index) unsigned char color[3] = {penColor[0], penColor[1], penColor[2]}; if (this->PointToToggle == index && this->PointAboutToBeToggled) - { + { invertShadow = !invertShadow; - } + } if (this->PointToDelete == index && this->PointAboutToBeDeleted) - { + { invertShadow = !invertShadow; color[0] = 255; color[1] = 0; color[2] = 0; - } + } if (this->CurrentPoint == index) - { + { radius = this->ScreenPointRadius * 1.3; color[0] = 255; color[1] = 0; color[2] = 255; - } + } painter->GetPen()->SetColor(color); painter->DrawArc(0.f, 0.f, radius, 0.f, 360.f); @@ -581,17 +581,17 @@ void vtkControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType index) painter->GetPen()->SetColor(color); if (this->PointToDelete == index && this->PointAboutToBeDeleted) - { + { painter->DrawLine(-radius, -radius, radius, radius); painter->DrawLine(-radius, radius, radius, -radius); - } + } painter->GetPen()->SetColor(penColor); if (this->ShowLabels && (/*index == 0 || index == this->GetNumberOfPoints()-1 || */ this->GetCurrentPoint() == index)) - { + { translation->Translate(0, radius+5); painter->SetTransform(translation); vtkStdString label = this->GetControlPointLabel(index); @@ -599,7 +599,7 @@ void vtkControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType index) vtkVector2f bounds[2]; painter->ComputeStringBounds(label, bounds[0].GetData()); if (bounds[1].GetX() != 0.0f && bounds[1].GetY() != 0.0f) - { + { float scale[2]; float position[2]; painter->GetTransform()->GetScale(scale); @@ -617,20 +617,20 @@ void vtkControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType index) // Pull the tooltip back in if it will go off the edge of the screen. float maxX = (this->Scene->GetViewWidth() - position[0])/scale[0]; if (bounds[0].GetX() >= maxX - bounds[1].GetX()) - { + { bounds[0].SetX(maxX - bounds[1].GetX()); - } + } // Pull the tooltip down in if it will go off the edge of the screen. float maxY = (this->Scene->GetViewHeight() - position[1])/scale[1]; if (bounds[0].GetY() >= maxY - bounds[1].GetY()) - { + { bounds[0].SetY(maxY - bounds[1].GetY()); - } + } painter->DrawRect(bounds[0].GetX(), bounds[0].GetY(), bounds[1].GetX(), bounds[1].GetY()); painter->DrawString(bounds[0].GetX()+5/scale[0], bounds[0].GetY()+3/scale[1], label); painter->GetBrush()->SetColorF(brushColor); - } } + } painter->GetPen()->SetOpacity(penOpacity); //painter->GetPen()->SetWidth(width); @@ -644,10 +644,10 @@ void vtkControlPointsItem::SelectPoint(double* currentPoint) { vtkIdType pointId = this->FindPoint(currentPoint); if (pointId == -1) - { + { vtkErrorMacro( << "try to select a point that doesn't exist"); return; - } + } this->SelectPoint(pointId); } @@ -655,9 +655,9 @@ void vtkControlPointsItem::SelectPoint(double* currentPoint) void vtkControlPointsItem::SelectPoint(vtkIdType pointId) { if (!this->Selection || this->Selection->LookupValue(pointId) != -1) - { + { return; - } + } this->Selection->InsertNextValue(pointId); this->GetScene()->SetDirty(true); } @@ -668,9 +668,9 @@ void vtkControlPointsItem::SelectAllPoints() this->DeselectAllPoints(); const int count = this->GetNumberOfPoints(); for (vtkIdType i = 0; i < count; ++i) - { + { this->SelectPoint(i); - } + } } //----------------------------------------------------------------------------- @@ -679,10 +679,10 @@ void vtkControlPointsItem::DeselectPoint(double* point) // make sure the point belongs to the list of points vtkIdType pointId = this->FindPoint(point); if (pointId == -1) - { + { vtkErrorMacro( << "try to deselect a point that doesn't exist"); return; - } + } this->DeselectPoint(pointId); } @@ -692,10 +692,10 @@ void vtkControlPointsItem::DeselectPoint(vtkIdType pointId) vtkIdType selectionPointId = this->Selection ? this->Selection->LookupValue(pointId) : -1; if (selectionPointId == -1) - { + { //vtkErrorMacro(<< "Point:" << pointId << " was not selected"); return; - } + } this->Selection->RemoveTuple(selectionPointId); this->GetScene()->SetDirty(true); } @@ -704,9 +704,9 @@ void vtkControlPointsItem::DeselectPoint(vtkIdType pointId) void vtkControlPointsItem::DeselectAllPoints() { if (this->GetNumberOfSelectedPoints() == 0) - { + { return; - } + } this->Selection->SetNumberOfTuples(0); this->GetScene()->SetDirty(true); } @@ -717,10 +717,10 @@ void vtkControlPointsItem::ToggleSelectPoint(double* currentPoint) // make sure the point belongs to the list of points vtkIdType pointId = this->FindPoint(currentPoint); if (pointId == -1) - { + { vtkErrorMacro( << "try to toggle a point that doesn't exist"); return; - } + } this->ToggleSelectPoint(pointId); } @@ -730,10 +730,10 @@ void vtkControlPointsItem::ToggleSelectPoint(vtkIdType pointId) vtkIdType selectionId = this->Selection ? this->Selection->LookupValue(pointId) : -1; if (selectionId != -1) - { + { this->DeselectPoint(pointId); return; - } + } this->SelectPoint(pointId); } @@ -743,20 +743,20 @@ bool vtkControlPointsItem::SelectPoints(const vtkVector2f& min, const vtkVector2 bool atLeast1PointSelected = false; const int numberOfPoints = this->GetNumberOfPoints(); for(vtkIdType i = 0; i < numberOfPoints; ++i) - { + { double point[4]; this->GetControlPoint(i, point); if (point[0] >= min.GetX() && point[0] <= max.GetX() && point[1] >= min.GetY() && point[1] <= max.GetY()) - { + { this->SelectPoint(i); atLeast1PointSelected = true; - } + } else - { + { this->DeselectPoint(i); - } } + } return atLeast1PointSelected; } @@ -815,9 +815,9 @@ vtkIdType vtkControlPointsItem::FindPoint(double* pos, double tolerance) bool vtkControlPointsItem::IsOverPoint(double* pos, vtkIdType pointId) { if (pointId < 0 || pointId >= this->GetNumberOfPoints()) - { + { return false; - } + } double screenPos[2]; this->Transform->TransformPoints(pos, screenPos, 1); @@ -853,7 +853,7 @@ vtkIdType vtkControlPointsItem::FindPoint(double* _pos) double minDist = VTK_DOUBLE_MAX; const int numberOfPoints = this->GetNumberOfPoints(); for(vtkIdType i = 0; i < numberOfPoints; ++i) - { + { double point[4]; this->GetControlPoint(i, point); vtkVector2f vpos1(point[0], point[1]); @@ -867,23 +867,23 @@ vtkIdType vtkControlPointsItem::FindPoint(double* _pos) (screenPoint[0] - screenPos[0]) * (screenPoint[0] - screenPos[0]) + (screenPoint[1] - screenPos[1]) * (screenPoint[1] - screenPos[1]); if (distance2 <= radius2) - { + { if (distance2 == 0.) - {// we found the best match ever + {// we found the best match ever return i; - } + } else if (distance2 < minDist) - {// we found something not too bad, maybe we can find closer + {// we found something not too bad, maybe we can find closer pointId = i; minDist = distance2; - } } + } // don't search any further if the x is already too large if (screenPoint[0] > (screenPos[0] + this->ScreenPointRadius * tolerance)) - { + { break; - } } + } return pointId; } @@ -892,14 +892,14 @@ vtkIdType vtkControlPointsItem::GetControlPointId(double* point) { const int numberOfPoints = this->GetNumberOfPoints(); for(vtkIdType i = 0; i < numberOfPoints; ++i) - { + { double controlPoint[4]; this->GetControlPoint(i, controlPoint); if (controlPoint[0] == point[0]) - { + { return i; - } } + } return -1; } @@ -910,16 +910,16 @@ ::GetControlPointsIds(vtkIdTypeArray* points, bool excludeFirstAndLast)const assert(points != 0); int numberOfPoints = this->GetNumberOfPoints(); if (excludeFirstAndLast) - { + { numberOfPoints -= 2; - } + } numberOfPoints = std::max(numberOfPoints, 0); points->SetNumberOfTuples(numberOfPoints); vtkIdType pointId = excludeFirstAndLast ? 1 : 0; for(vtkIdType i = 0; i < numberOfPoints; ++i) - { + { points->SetValue(i, pointId++); - } + } } //----------------------------------------------------------------------------- void vtkControlPointsItem::AddPointId(vtkIdType addedPointId) @@ -928,17 +928,17 @@ void vtkControlPointsItem::AddPointId(vtkIdType addedPointId) // offset all the point ids const int selectionCount = this->GetNumberOfSelectedPoints(); for (vtkIdType i = 0; i < selectionCount; ++i) - { + { vtkIdType pointId = this->Selection->GetValue(i); if (pointId >= addedPointId) - { + { this->Selection->SetValue(i, ++pointId); - } } + } if (this->CurrentPoint >= addedPointId) - { + { this->SetCurrentPoint(this->CurrentPoint + 1); - } + } } //----------------------------------------------------------------------------- @@ -959,9 +959,9 @@ vtkIdType vtkControlPointsItem::RemovePoint(vtkIdType pointId) vtkIdType vtkControlPointsItem::RemovePointId(vtkIdType pointId) { if(!this->IsPointRemovable(pointId)) - { + { return pointId; - } + } this->StartChanges(); @@ -971,19 +971,19 @@ vtkIdType vtkControlPointsItem::RemovePointId(vtkIdType pointId) const vtkIdType selectionCount = this->GetNumberOfSelectedPoints(); for (vtkIdType i = 0; i < selectionCount; ++i) - { + { vtkIdType selectedPointId = this->Selection->GetValue(i); if (selectedPointId > pointId) - { + { this->Selection->SetValue(i, --selectedPointId); - } } + } if (this->CurrentPoint > pointId || this->CurrentPoint == this->GetNumberOfPoints() - 1) - { + { this->SetCurrentPoint(this->CurrentPoint - 1); - } + } this->EndChanges(); return pointId; @@ -993,9 +993,9 @@ vtkIdType vtkControlPointsItem::RemovePointId(vtkIdType pointId) void vtkControlPointsItem::SetCurrentPoint(vtkIdType index) { if (index == this->CurrentPoint) - { + { return; - } + } this->CurrentPoint = index; this->InvokeEvent(vtkControlPointsItem::CurrentPointChangedEvent, reinterpret_cast(this->CurrentPoint)); @@ -1017,45 +1017,45 @@ bool vtkControlPointsItem::MouseButtonPressEvent(const vtkContextMouseEvent &mou vtkIdType pointUnderMouse = this->FindPoint(pos); if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { if (pointUnderMouse != -1) - { + { this->SetCurrentPoint(pointUnderMouse); return true; - } + } else if (pointUnderMouse == -1 && this->GetNumberOfSelectedPoints() <= 1 && !this->StrokeMode) - { + { this->ClampValidPos(pos); vtkIdType addedPoint = this->AddPoint(pos); this->SetCurrentPoint(addedPoint); return true; - } + } else - { + { this->SetCurrentPoint(-1); - } - return true; } + return true; + } if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON && pointUnderMouse != -1) - { + { this->PointToToggle = pointUnderMouse; this->PointAboutToBeToggled = true; this->GetScene()->SetDirty(true); return true; - } + } if (mouse.GetButton() == vtkContextMouseEvent::MIDDLE_BUTTON && pointUnderMouse != -1) - { + { this->PointToDelete = pointUnderMouse; this->PointAboutToBeDeleted = true; this->GetScene()->SetDirty(true); return true; - } + } return false; } @@ -1064,24 +1064,24 @@ bool vtkControlPointsItem::MouseButtonPressEvent(const vtkContextMouseEvent &mou bool vtkControlPointsItem::MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON) - { + { if (this->Selection->GetNumberOfTuples()) - { + { this->DeselectAllPoints(); - } + } else - { + { this->SelectAllPoints(); - } - return true; } + return true; + } bool res = this->MouseButtonPressEvent(mouse); if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON && this->CurrentPoint != -1) - { + { this->InvokeEvent(vtkControlPointsItem::CurrentPointEditEvent, reinterpret_cast(this->CurrentPoint)); - } + } return res; } @@ -1092,118 +1092,118 @@ bool vtkControlPointsItem::MouseMoveEvent(const vtkContextMouseEvent &mouse) this->TransformScreenToData(mousePos, mousePos); if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { if (this->StrokeMode) - { + { this->StartInteractionIfNotStarted(); this->Stroke(mousePos); this->Interaction(); - } + } else if (this->CurrentPoint == -1 && this->GetNumberOfSelectedPoints() > 1) - { + { vtkVector2f deltaPos = mouse.GetPos() - mouse.GetLastPos(); if(this->IsEndPointPicked()) - { + { if(!this->GetEndPointsMovable()) - { + { return false; - } + } else if(this->GetEndPointsXMovable()) - { + { deltaPos.SetY(0); - } + } else if(this->GetEndPointsYMovable()) - { + { deltaPos.SetX(0); - } } + } this->StartInteractionIfNotStarted(); if (vtkIdTypeArray* points = this->GetSelection()) - { + { // must stay valid after each individual point move points->Register(this); this->MovePoints(deltaPos, points); points->UnRegister(this); - } + } this->Interaction(); - } + } else if (this->CurrentPoint != -1) - { + { vtkVector2f curPos(mousePos); if(this->IsEndPointPicked()) - { + { double currentPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(this->CurrentPoint, currentPoint); if(!this->GetEndPointsMovable()) - { + { return false; - } + } else if(this->GetEndPointsXMovable()) - { + { curPos.SetY(currentPoint[1]); - } + } else if(this->GetEndPointsYMovable()) - { + { curPos.SetX(currentPoint[0]); - } } + } this->StartInteractionIfNotStarted(); this->SetCurrentPointPos(curPos); this->Interaction(); - } } + } if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON) - { + { if (this->PointToToggle == -1) - { + { return false; - } + } double pos[2]; pos[0] = mousePos[0]; pos[1] = mousePos[1]; vtkIdType pointUnderCursor = this->FindPoint(pos); if ((pointUnderCursor == this->PointToToggle) != this->PointAboutToBeToggled) - { + { this->PointAboutToBeToggled = !this->PointAboutToBeToggled; this->GetScene()->SetDirty(true); - } } + } this->MouseMoved = true; if (mouse.GetButton() == vtkContextMouseEvent::MIDDLE_BUTTON) - { + { if (this->PointToDelete == -1) - { + { // allow chart ruber band to work return false; - } + } double pos[2]; pos[0] = mousePos[0]; pos[1] = mousePos[1]; vtkIdType pointUnderCursor = this->FindPoint(pos); if ((pointUnderCursor == this->PointToDelete) != this->PointAboutToBeDeleted) - { + { this->PointAboutToBeDeleted = !this->PointAboutToBeDeleted; this->GetScene()->SetDirty(true); - } - return true; } + return true; + } if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON && this->CurrentPoint == -1) - { + { return false; - } + } if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON) - { + { return false; - } + } return true; } @@ -1219,9 +1219,9 @@ void vtkControlPointsItem::SetCurrentPointPos(const vtkVector2f& newPos) vtkIdType vtkControlPointsItem::SetPointPos(vtkIdType point, const vtkVector2f& newPos) { if (point == -1) - { + { return point; - } + } // Make sure the new point is inside the boundaries of the function double boundedPos[2]; @@ -1230,57 +1230,57 @@ vtkIdType vtkControlPointsItem::SetPointPos(vtkIdType point, const vtkVector2f& this->ClampValidPos(boundedPos); if (!this->SwitchPointsMode) - { + { // Stop mode. // You can't move a point past another point. if (point > 0) - { + { double previousPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(point - 1, previousPoint); boundedPos[0] = std::max(previousPoint[0], boundedPos[0]); - } + } if (point < this->GetNumberOfPoints() - 1) - { + { double nextPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(point + 1, nextPoint); boundedPos[0] = std::min(boundedPos[0], nextPoint[0]); - } } + } else - { + { // Switch mode. // Moving a point to the right of the next one, makes it current. // and moving a point to the left of the previous one makes it current. if (point > 0) - { + { double previousPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(point - 1, previousPoint); while (boundedPos[0] < previousPoint[0]) - { + { point = point - 1; if (point == 0) - { + { break; - } + } // maybe the move is that important that it went over multiple points this->GetControlPoint(point - 1, previousPoint); - } } + } if (point < this->GetNumberOfPoints() - 1) - { + { double nextPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(point + 1, nextPoint); while (boundedPos[0] > nextPoint[0]) - { + { point = point + 1; if (point == this->GetNumberOfPoints() - 1) - { + { break; - } - this->GetControlPoint(point + 1, nextPoint); } + this->GetControlPoint(point + 1, nextPoint); } } + } double currentPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(point, currentPoint); currentPoint[0] = boundedPos[0]; @@ -1323,7 +1323,7 @@ void vtkControlPointsItem::MovePoints(const vtkVector2f& translation, vtkIdTypeA int end = tX < 0.f ? count : -1; int step = tX < 0.f ? 1 : -1; for (vtkIdType i = start; i != end; i+=step) - { + { vtkIdType pointId = pointIds->GetValue(i); double currentPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(pointId, currentPoint); @@ -1341,7 +1341,7 @@ void vtkControlPointsItem::MovePoints(const vtkVector2f& translation, vtkIdTypeA // addedSelection->InsertNextValue(newIdx); // } // end "don't support 'switch' mode yet" - } + } // don't support 'switch' mode yet //this->SelectPoints(addedSelection); this->SwitchPointsMode = oldSwitchPoints; @@ -1363,9 +1363,9 @@ void vtkControlPointsItem::SpreadPoints(float factor, vtkIdTypeArray* pointIds) { assert(pointIds); if (pointIds->GetNumberOfTuples() == 0) - { + { return; - } + } this->StartChanges(); double min[2], max[2], center[2]; @@ -1387,55 +1387,55 @@ void vtkControlPointsItem::SpreadPoints(float factor, vtkIdTypeArray* pointIds) vtkIdType step = 1; vtkIdType median = -1; // not needed when factor >= 0 if (factor < 0.f) - { + { // search median for (vtkIdType i = 0; i < end; ++i) - { + { vtkIdType pointId = pointIds->GetValue(i); this->GetControlPoint(pointId, point); if (point[0] > center[0]) - { + { median = i; break; - } } + } if (median == -1) - { + { median = pointIds->GetNumberOfTuples() - 1; - } + } start = median - 1; end = -1; step = -1; - } + } vtkIdType i; for (i = start; i != end; i+=step) - { + { vtkIdType pointId = pointIds->GetValue(i); this->GetControlPoint(pointId, point); if (point[0] > center[0] || (i != start && point[0] == center[0])) - { + { break; - } + } double tX = -factor; tX *= (min[0] != center[0]) ? (center[0] - point[0]) / (center[0] - min[0]) : fabs(point[0]) / 100.; vtkVector2f newPos(std::min(point[0] + tX, center[0]), point[1]); this->SetPointPos(pointId, newPos); - } + } // Right part start = pointIds->GetNumberOfTuples() - 1; end = i - 1; step = -1; if (factor < 0.f) - { + { start = median; end = pointIds->GetNumberOfTuples(); step = 1; - } + } for (i = start; i != end; i+=step) - { + { vtkIdType pointId = pointIds->GetValue(i); this->GetControlPoint(pointId, point); assert(point[0] >= center[0]); @@ -1445,7 +1445,7 @@ void vtkControlPointsItem::SpreadPoints(float factor, vtkIdTypeArray* pointIds) fabs(point[0]) / 100.; vtkVector2f newPos(std::max(point[0] + tX, center[0]), point[1]); this->SetPointPos(pointId, newPos); - } + } this->EndChanges(); } @@ -1463,14 +1463,14 @@ vtkVector2f vtkControlPointsItem::GetCenterOfMass(vtkIdTypeArray* pointIDs)const double average[4] = {0., 0., 0., 0.}; const vtkIdType pointCount = pointIDs->GetNumberOfTuples(); for (vtkIdType i = 0; i < pointCount; ++i) - { + { double point[4]; this->GetControlPoint(pointIDs->GetValue(i), point); average[0] += point[0]; // x average[1] += point[1]; // y average[2] += point[2]; // midpoint average[3] += point[3]; // sharpness - } + } average[0] /= pointCount; // x average[1] /= pointCount; // y average[2] /= pointCount; // midpoint @@ -1488,7 +1488,7 @@ void vtkControlPointsItem::Stroke(const vtkVector2f& newPos) // last point if (this->CurrentPoint != -1) - { + { vtkIdType lastPointId = this->CurrentPoint; double lastPoint[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(lastPointId, lastPoint); @@ -1497,58 +1497,58 @@ void vtkControlPointsItem::Stroke(const vtkVector2f& newPos) this->ScreenPointRadius *= pointSpacing; // ignore the stroke if it is too close from the last point if (this->FindPoint(pos) == lastPointId) - { + { this->ScreenPointRadius = oldScreenPointRadius; return; - } + } this->ScreenPointRadius = oldScreenPointRadius; // For the first case or when the new pos share the same X (but not the // same y) then we just have to modify the last point if (!this->MouseMoved || lastPoint[0] == pos[0]) - { + { lastPoint[0] = pos[0]; lastPoint[1] = pos[1]; this->SetControlPoint(this->CurrentPoint, lastPoint); return; - } + } assert(lastPoint[0] != pos[0]); // CurrentPoint != -1 && MouseMoved // Starting from the last point, we search points (forward or backward) to see // if there are points that can be removed. int count = this->GetNumberOfPoints(); if (pos[0] > lastPoint[0] && lastPointId < count - 1) - { + { // search if there are points between pos and lastPoint double point[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(lastPointId + 1, point); while (pos[0] >= point[0]) - { + { this->RemovePoint(point); count = this->GetNumberOfPoints(); if (lastPointId == count - 1) - { + { break; - } - this->GetControlPoint(lastPointId + 1, point); } + this->GetControlPoint(lastPointId + 1, point); } + } else if (pos[0] < lastPoint[0] && lastPointId > 0) - { + { // search if there are points between pos and lastPoint double point[4] = {0.0, 0.0, 0.0, 0.0}; this->GetControlPoint(lastPointId - 1, point); while (pos[0] <= point[0]) - { + { this->RemovePoint(point); --lastPointId; if (lastPointId == 0) - { + { break; - } - this->GetControlPoint(lastPointId - 1, point); } + this->GetControlPoint(lastPointId - 1, point); } } + } #ifndef NDEBUG const int oldNumberOfPoints = this->GetNumberOfPoints(); #endif @@ -1566,47 +1566,47 @@ void vtkControlPointsItem::EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY)) bool vtkControlPointsItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) { if (this->GetInteractionsCount()) - { + { this->EndInteraction(); - } + } if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { return true; - } + } if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON && this->PointToToggle != -1) - { + { if (this->PointAboutToBeToggled) - { + { this->ToggleSelectPoint(this->PointToToggle); this->PointToToggle = -1; this->PointAboutToBeToggled = false; - } - return true; } + return true; + } if (mouse.GetButton() == vtkContextMouseEvent::MIDDLE_BUTTON && this->PointToDelete != -1) - { + { if (this->PointAboutToBeDeleted) - { + { // If EnforceValidFunction is true, we don't want less than 2 points if (this->IsPointRemovable(this->PointToDelete)) - { + { double point[4]; this->GetControlPoint(this->PointToDelete, point); this->RemovePoint(point); this->PointToDelete = -1; this->PointAboutToBeDeleted = false; - } + } else - { + { this->PointToDelete = -1; this->PointAboutToBeDeleted = false; this->GetScene()->SetDirty(true); - } } - return true; } + return true; + } return false; } @@ -1620,157 +1620,157 @@ bool vtkControlPointsItem::KeyPressEvent(const vtkContextKeyEvent &key) bool control = key.GetInteractor()->GetControlKey() != 0; bool current = !select && !move && !control; if (current) - { + { if (key.GetInteractor()->GetKeySym() == vtkStdString("Right") || key.GetInteractor()->GetKeySym() == vtkStdString("Up")) - { + { this->SetCurrentPoint( std::min(this->GetNumberOfPoints() -1, this->GetCurrentPoint() + 1)); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("Left") || key.GetInteractor()->GetKeySym() == vtkStdString("Down")) - { + { this->SetCurrentPoint( std::max(0, static_cast(this->GetCurrentPoint()) - 1)); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("End")) - { + { this->SetCurrentPoint(this->GetNumberOfPoints() - 1); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("Home")) - { + { this->SetCurrentPoint(0); - } } + } else if (select) - { + { if (key.GetInteractor()->GetKeySym() == std::string("Right") || key.GetInteractor()->GetKeySym() == std::string("Up")) - { + { this->SelectPoint(this->CurrentPoint); this->SetCurrentPoint( std::min(this->GetNumberOfPoints() -1, this->GetCurrentPoint() + 1)); this->SelectPoint(this->CurrentPoint); - } + } else if (key.GetInteractor()->GetKeySym() == std::string("Left") || key.GetInteractor()->GetKeySym() == std::string("Down")) - { + { this->SelectPoint(this->CurrentPoint); this->SetCurrentPoint( std::max(0, static_cast(this->GetCurrentPoint()) - 1)); this->SelectPoint(this->CurrentPoint); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("End")) - { + { vtkIdType newCurrentPointId = this->GetNumberOfPoints() - 1; for (vtkIdType pointId = this->CurrentPoint; pointId < newCurrentPointId; ++pointId) - { + { this->SelectPoint(pointId); - } + } this->SelectPoint(newCurrentPointId); this->SetCurrentPoint(newCurrentPointId); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("Home")) - { + { vtkIdType newCurrentPointId = 0; for (vtkIdType pointId = this->CurrentPoint; pointId > newCurrentPointId; --pointId) - { + { this->SelectPoint(pointId); - } + } this->SelectPoint(newCurrentPointId); this->SetCurrentPoint(newCurrentPointId); - } } + } else if (move) - { + { vtkVector2f translate(0,0); if (key.GetInteractor()->GetKeySym() == std::string("Up")) - { + { translate = translate + vtkVector2f(0., 1.); - } + } if (key.GetInteractor()->GetKeySym() == std::string("Down")) - { + { translate = translate + vtkVector2f(0., -1.); - } + } if (key.GetInteractor()->GetKeySym() == std::string("Right")) - { + { translate = translate + vtkVector2f(1., 0.); - } + } if (key.GetInteractor()->GetKeySym() == std::string("Left")) - { + { translate = translate + vtkVector2f(-1., 0.); - } + } if (translate.GetX() != 0.f || translate.GetY() != 0.f) - { + { double bounds[4]; this->GetBounds(bounds); float step = control ? 0.001 : 0.01; translate.SetX( translate.GetX() * (bounds[1] - bounds[0]) * step); translate.SetY( translate.GetY() * (bounds[3] - bounds[2]) * step); if (this->GetNumberOfSelectedPoints()) - { + { this->StartInteractionIfNotStarted(); if (vtkIdTypeArray* points = this->GetSelection()) - { + { points->Register(this); // must stay valid after each individual move this->MovePoints(translate, points); points->UnRegister(this); - } + } this->Interaction(); - } + } else - { + { this->StartInteractionIfNotStarted(); this->MoveCurrentPoint(translate); this->Interaction(); - } } + } else if (key.GetInteractor()->GetKeySym() == std::string("plus")) - { + { this->StartInteractionIfNotStarted(); if (vtkIdTypeArray* pointIds = this->GetSelection()) - { + { pointIds->Register(this); // must stay valid after each individual move this->SpreadPoints(1., pointIds); pointIds->UnRegister(this); - } + } this->Interaction(); - } + } else if (key.GetInteractor()->GetKeySym() == std::string("minus")) - { + { this->StartInteractionIfNotStarted(); if (vtkIdTypeArray* pointIds = this->GetSelection()) - { + { pointIds->Register(this); // must stay valid after each individual move this->SpreadPoints(-1., pointIds); pointIds->UnRegister(this); - } + } this->Interaction(); - } } + } else if (control) - { + { if (key.GetInteractor()->GetKeySym() == std::string("a")) - { + { this->SelectAllPoints(); - } } + } if (key.GetInteractor()->GetKeySym() == vtkStdString("space")) - { + { this->ToggleSelectPoint(this->GetCurrentPoint()); - } + } else if (key.GetInteractor()->GetKeySym() == vtkStdString("Escape")) - { + { this->DeselectAllPoints(); - } + } return this->Superclass::KeyPressEvent(key); } @@ -1779,14 +1779,14 @@ bool vtkControlPointsItem::KeyReleaseEvent(const vtkContextKeyEvent &key) { if (key.GetInteractor()->GetKeySym() == std::string("Delete") || key.GetInteractor()->GetKeySym() == std::string("BackSpace")) - { + { vtkIdType removedPoint = this->RemovePoint(this->GetCurrentPoint()); if (key.GetInteractor()->GetKeySym() == std::string("BackSpace")) - { + { this->SetCurrentPoint(removedPoint > 0 ? removedPoint - 1 : 0); - } - return true; } + return true; + } return this->Superclass::KeyPressEvent(key); } @@ -1801,26 +1801,26 @@ bool vtkControlPointsItem::IsEndPointPicked() { int numPts = this->GetNumberOfPoints(); if(numPts<=0) - { + { return false; - } + } if(this->CurrentPoint==0 || this->CurrentPoint==numPts-1) - { + { return true; - } + } vtkIdTypeArray* selection = this->GetSelection(); if(selection && selection->GetNumberOfTuples()>0) - { + { vtkIdType pid; for (vtkIdType i = 0; i < selection->GetNumberOfTuples(); ++i) - { + { pid=selection->GetValue(i); if(pid==0 || pid==numPts-1) - { + { return true; - } } } + } return false; } @@ -1829,14 +1829,14 @@ bool vtkControlPointsItem::IsPointRemovable(vtkIdType pointId) { vtkIdType numPts = this->GetNumberOfPoints(); if (this->EnforceValidFunction && numPts<= 2) - { + { return false; - } + } if(pointId != -1 && !this->GetEndPointsRemovable() && (pointId==0 || pointId==numPts-1)) - { + { return false; - } + } return true; } @@ -1845,13 +1845,13 @@ vtkStdString vtkControlPointsItem::GetControlPointLabel(vtkIdType pointId) { vtkStdString result; if (this->LabelFormat) - { + { char *buffer = new char[1024]; double point[4]; this->GetControlPoint(pointId, point); sprintf(buffer, this->LabelFormat, point[0], point[1], point[2], point[3]); result = buffer; delete []buffer; - } + } return result; } diff --git a/Charts/Core/vtkLookupTableItem.cxx b/Charts/Core/vtkLookupTableItem.cxx index e6c1703a33e..a9c5330591e 100644 --- a/Charts/Core/vtkLookupTableItem.cxx +++ b/Charts/Core/vtkLookupTableItem.cxx @@ -37,10 +37,10 @@ vtkLookupTableItem::vtkLookupTableItem() vtkLookupTableItem::~vtkLookupTableItem() { if (this->LookupTable) - { + { this->LookupTable->Delete(); this->LookupTable = 0; - } + } } //----------------------------------------------------------------------------- @@ -49,14 +49,14 @@ void vtkLookupTableItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "LookupTable: "; if (this->LookupTable) - { + { os << endl; this->LookupTable->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- @@ -64,29 +64,29 @@ void vtkLookupTableItem::ComputeBounds(double* bounds) { this->Superclass::ComputeBounds(bounds); if (this->LookupTable) - { + { double* range = this->LookupTable->GetRange(); bounds[0] = range[0]; bounds[1] = range[1]; - } + } } //----------------------------------------------------------------------------- void vtkLookupTableItem::SetLookupTable(vtkLookupTable* t) { if (t == this->LookupTable) - { + { return; - } + } if (this->LookupTable) - { + { this->LookupTable->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(LookupTable, vtkLookupTable, t); if (t) - { + { t->AddObserver(vtkCommand::ModifiedEvent, this->Callback); - } + } this->ScalarsToColorsModified(this->LookupTable, vtkCommand::ModifiedEvent, 0); } @@ -97,13 +97,13 @@ void vtkLookupTableItem::ComputeTexture() this->GetBounds(bounds); if (bounds[0] == bounds[1] || !this->LookupTable) - { + { return; - } + } if (this->Texture == 0) - { + { this->Texture = vtkImageData::New(); - } + } // Could depend of the screen resolution const int dimension = 256; double values[256]; @@ -114,20 +114,20 @@ void vtkLookupTableItem::ComputeTexture() this->Texture->AllocateScalars(VTK_UNSIGNED_CHAR, 4); // TODO: Support log scale ? for (int i = 0; i < dimension; ++i) - { + { values[i] = bounds[0] + i * (bounds[1] - bounds[0]) / (dimension - 1); - } + } unsigned char* ptr = reinterpret_cast(this->Texture->GetScalarPointer(0,0,0)); this->LookupTable->MapScalarsThroughTable2( values, ptr, VTK_DOUBLE, dimension, 1, 4); if (this->Opacity != 1.) - { + { for (int i = 0; i < dimension; ++i) - { + { ptr[3] = static_cast(this->Opacity * ptr[3]); ptr+=4; - } } + } return; } diff --git a/Charts/Core/vtkPiecewiseControlPointsItem.cxx b/Charts/Core/vtkPiecewiseControlPointsItem.cxx index a645b4bc26f..8df0a16854a 100644 --- a/Charts/Core/vtkPiecewiseControlPointsItem.cxx +++ b/Charts/Core/vtkPiecewiseControlPointsItem.cxx @@ -44,11 +44,11 @@ vtkPiecewiseControlPointsItem::vtkPiecewiseControlPointsItem() vtkPiecewiseControlPointsItem::~vtkPiecewiseControlPointsItem() { if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->RemoveObserver(this->Callback); this->PiecewiseFunction->Delete(); this->PiecewiseFunction = 0; - } + } } //----------------------------------------------------------------------------- @@ -57,32 +57,32 @@ void vtkPiecewiseControlPointsItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "PiecewiseFunction: "; if (this->PiecewiseFunction) - { + { os << endl; this->PiecewiseFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- void vtkPiecewiseControlPointsItem::emitEvent(unsigned long event, void* params) { if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->InvokeEvent(event, params); - } + } } //----------------------------------------------------------------------------- vtkMTimeType vtkPiecewiseControlPointsItem::GetControlPointsMTime() { if (this->PiecewiseFunction) - { + { return this->PiecewiseFunction->GetMTime(); - } + } return this->GetMTime(); } @@ -90,20 +90,20 @@ vtkMTimeType vtkPiecewiseControlPointsItem::GetControlPointsMTime() void vtkPiecewiseControlPointsItem::SetPiecewiseFunction(vtkPiecewiseFunction* t) { if (t == this->PiecewiseFunction) - { + { return; - } + } if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(PiecewiseFunction, vtkPiecewiseFunction, t); if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->AddObserver(vtkCommand::StartEvent, this->Callback); this->PiecewiseFunction->AddObserver(vtkCommand::ModifiedEvent, this->Callback); this->PiecewiseFunction->AddObserver(vtkCommand::EndEvent, this->Callback); - } + } this->ResetBounds(); this->ComputePoints(); } @@ -129,20 +129,20 @@ void vtkPiecewiseControlPointsItem::SetControlPoint(vtkIdType index, double* new this->PiecewiseFunction->GetNodeValue(index, oldPos); if (newPos[0] != oldPos[0] || newPos[1] != oldPos[1] || newPos[2] != oldPos[2]) - { + { this->StartChanges(); this->PiecewiseFunction->SetNodeValue(index, newPos); this->EndChanges(); - } + } } //----------------------------------------------------------------------------- void vtkPiecewiseControlPointsItem::EditPoint(float tX, float tY) { if (!this->PiecewiseFunction) - { + { return; - } + } this->StartChanges(); @@ -152,12 +152,12 @@ void vtkPiecewiseControlPointsItem::EditPoint(float tX, float tY) xvms[3] += tY; this->PiecewiseFunction->SetNodeValue(this->CurrentPoint, xvms); if (this->CurrentPoint > 0) - { + { this->PiecewiseFunction->GetNodeValue(this->CurrentPoint - 1, xvms); xvms[2] += tX; xvms[3] += tY; this->PiecewiseFunction->SetNodeValue(this->CurrentPoint - 1, xvms); - } + } this->EndChanges(); } @@ -166,9 +166,9 @@ void vtkPiecewiseControlPointsItem::EditPoint(float tX, float tY) vtkIdType vtkPiecewiseControlPointsItem::AddPoint(double* newPos) { if (!this->PiecewiseFunction) - { + { return -1; - } + } this->StartChanges(); vtkIdType addedPoint = this->PiecewiseFunction->AddPoint(newPos[0], newPos[1]); @@ -182,13 +182,13 @@ vtkIdType vtkPiecewiseControlPointsItem::AddPoint(double* newPos) vtkIdType vtkPiecewiseControlPointsItem::RemovePoint(double* currentPoint) { if (!this->PiecewiseFunction) - { + { return -1; - } + } if (!this->IsPointRemovable(this->GetControlPointId(currentPoint))) - { + { return -1; - } + } this->StartChanges(); diff --git a/Charts/Core/vtkPiecewiseFunctionItem.cxx b/Charts/Core/vtkPiecewiseFunctionItem.cxx index b2696e0bd8d..c72667be203 100644 --- a/Charts/Core/vtkPiecewiseFunctionItem.cxx +++ b/Charts/Core/vtkPiecewiseFunctionItem.cxx @@ -41,11 +41,11 @@ vtkPiecewiseFunctionItem::vtkPiecewiseFunctionItem() vtkPiecewiseFunctionItem::~vtkPiecewiseFunctionItem() { if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->RemoveObserver(this->Callback); this->PiecewiseFunction->Delete(); this->PiecewiseFunction = 0; - } + } } //----------------------------------------------------------------------------- @@ -54,14 +54,14 @@ void vtkPiecewiseFunctionItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "PiecewiseFunction: "; if (this->PiecewiseFunction) - { + { os << endl; this->PiecewiseFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } } //----------------------------------------------------------------------------- @@ -69,29 +69,29 @@ void vtkPiecewiseFunctionItem::ComputeBounds(double* bounds) { this->Superclass::ComputeBounds(bounds); if (this->PiecewiseFunction) - { + { double* range = this->PiecewiseFunction->GetRange(); bounds[0] = range[0]; bounds[1] = range[1]; - } + } } //----------------------------------------------------------------------------- void vtkPiecewiseFunctionItem::SetPiecewiseFunction(vtkPiecewiseFunction* t) { if (t == this->PiecewiseFunction) - { + { return; - } + } if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->RemoveObserver(this->Callback); - } + } vtkSetObjectBodyMacro(PiecewiseFunction, vtkPiecewiseFunction, t); if (t) - { + { t->AddObserver(vtkCommand::ModifiedEvent, this->Callback); - } + } this->ScalarsToColorsModified(this->PiecewiseFunction, vtkCommand::ModifiedEvent, 0); } @@ -102,13 +102,13 @@ void vtkPiecewiseFunctionItem::ComputeTexture() this->GetBounds(bounds); if (bounds[0] == bounds[1] || !this->PiecewiseFunction) - { + { return; - } + } if (this->Texture == 0) - { + { this->Texture = vtkImageData::New(); - } + } const int dimension = this->GetTextureWidth(); double* values = new double[dimension]; @@ -122,29 +122,29 @@ void vtkPiecewiseFunctionItem::ComputeTexture() unsigned char* ptr = reinterpret_cast(this->Texture->GetScalarPointer(0,0,0)); if (this->MaskAboveCurve || this->PolyLinePen->GetLineType() != vtkPen::NO_PEN) - { + { this->Shape->SetNumberOfPoints(dimension); double step = (bounds[1] - bounds[0]) / dimension; for (int i = 0; i < dimension; ++i) - { + { this->Pen->GetColor(ptr); ptr[3] = static_cast(values[i] * this->Opacity * 255 + 0.5); assert(values[i] <= 1. && values[i] >= 0.); this->Shape->SetPoint(i, bounds[0] + step * i, values[i]); ptr+=4; - } - this->Shape->Modified(); } + this->Shape->Modified(); + } else - { + { for (int i = 0; i < dimension; ++i) - { + { this->Pen->GetColor(ptr); ptr[3] = static_cast(values[i] * this->Opacity * 255 + 0.5); assert(values[i] <= 1. && values[i] >= 0.); ptr+=4; - } } + } delete[] values; return; } diff --git a/Charts/Core/vtkPiecewisePointHandleItem.cxx b/Charts/Core/vtkPiecewisePointHandleItem.cxx index d07f809f5ce..93f19ab2110 100644 --- a/Charts/Core/vtkPiecewisePointHandleItem.cxx +++ b/Charts/Core/vtkPiecewisePointHandleItem.cxx @@ -32,10 +32,10 @@ #include enum enumPointHandleType - { +{ enSharpNess=0, enMidPoint - }; +}; class PointHandle { @@ -43,7 +43,7 @@ class PointHandle void Init(float x, float y, vtkIdType idx, enumPointHandleType type, float val, float distance, double sceneOrigin[2]) - { + { this->Position[0]=x; this->Position[1]=y; this->PointIndex = idx; @@ -52,11 +52,11 @@ class PointHandle this->fDistance = distance; this->ScenePos[0]=sceneOrigin[0]+x; this->ScenePos[1]=sceneOrigin[1]+y; - }; + }; void DrawCircle(vtkContext2D* painter, float radius) - { + { painter->DrawArc(this->Position[0], this->Position[1], radius, 0.f, 360.f); - }; + }; float Position[2]; float ScenePos[2]; vtkIdType PointIndex; @@ -92,33 +92,33 @@ vtkPiecewisePointHandleItem::~vtkPiecewisePointHandleItem() { this->SetPiecewiseFunction(0); if (this->Callback) - { + { this->Callback->Delete(); this->Callback = 0; - } + } delete this->Internal; } // ---------------------------------------------------------------------------- void vtkPiecewisePointHandleItem::SetParent(vtkAbstractContextItem* parent) { if(this->Parent == parent) - { + { return; - } + } else if(this->Parent) - { + { if (this->PiecewiseFunction) - { + { this->Parent->RemoveObserver(this->Callback); - } - } + + } this->Superclass::SetParent(parent); if(parent) - { + { this->Parent->AddObserver(vtkControlPointsItem::CurrentPointChangedEvent, this->Callback); - } + } } //----------------------------------------------------------------------------- @@ -128,10 +128,10 @@ bool vtkPiecewisePointHandleItem::Paint(vtkContext2D *painter) this->GetParent()); if(!parentControl || parentControl->GetCurrentPoint()<0 || !this->GetPiecewiseFunction()) - { + { this->CurrentPointIndex = -1; return true; - } + } vtkIdType currentIdx = parentControl->GetCurrentPoint(); this->CurrentPointIndex = currentIdx; double point[4]; @@ -164,15 +164,15 @@ bool vtkPiecewisePointHandleItem::Paint(vtkContext2D *painter) double preMid=0.0, preSharp=0.0, curMid=point[2], curSharp=point[3]; double prePoint[4], nxtPoint[4]; if(preIdx>=0) - { + { this->PiecewiseFunction->GetNodeValue(preIdx,prePoint); preMid=prePoint[2]; preSharp=prePoint[3]; - } + } if(nxtIdxGetNumberOfPoints()) - { + { this->PiecewiseFunction->GetNodeValue(nxtIdx,nxtPoint); preMid=prePoint[2]; preSharp=prePoint[3]; - } + } // The following calculations are to find out the correct // handle positions to draw. The handle positions are relative @@ -221,17 +221,17 @@ bool vtkPiecewisePointHandleItem::Paint(vtkContext2D *painter) painter->DrawLine(-(ptRadius+blxdistance*(1-preMid)), 0, -ptRadius, 0); for(int i=0; i<4; i++) - { + { if (i==this->MouseOverHandleIndex) - { + { painter->GetBrush()->SetColor(255, 0, 255); - } + } else - { + { painter->GetBrush()->SetColor(0, 200, 0); - } - this->Internal->PointHandles[i].DrawCircle(painter, radius); } + this->Internal->PointHandles[i].DrawCircle(painter, radius); + } painter->PopMatrix(); painter->GetPen()->SetColor(penColor); @@ -247,9 +247,9 @@ bool vtkPiecewisePointHandleItem::Hit(const vtkContextMouseEvent &mouse) { float pos[2] = { mouse.GetScenePos().GetX(), mouse.GetScenePos().GetY() }; if (this->IsOverHandle(pos) >= 0) - { + { return true; - } + } return false; } @@ -261,13 +261,13 @@ int vtkPiecewisePointHandleItem::IsOverHandle( this->GetParent()); if(!parentControl || parentControl->GetCurrentPoint()<0 || !this->GetPiecewiseFunction() || !this->Scene->GetLastPainter()) - { + { return -1; - } + } // we have four screen handles to check for(int i=0; i<4; ++i) - { + { double sceneHandlePoint[2]={ this->Internal->PointHandles[i].ScenePos[0], this->Internal->PointHandles[i].ScenePos[1]}; @@ -280,10 +280,10 @@ int vtkPiecewisePointHandleItem::IsOverHandle( double radius2 = this->HandleRadius * this->HandleRadius * tolerance * tolerance; if(distance2 <= radius2) - { + { return i; - } } + } return -1; } @@ -292,9 +292,9 @@ int vtkPiecewisePointHandleItem::IsOverHandle( bool vtkPiecewisePointHandleItem::MouseMoveEvent(const vtkContextMouseEvent &mouse) { if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { if(this->MouseOverHandleIndex >= 0) - { + { PointHandle* activeHandle = &this->Internal->PointHandles[this->MouseOverHandleIndex]; float deltaX = mouse.GetScenePos().GetX() - activeHandle->ScenePos[0]; @@ -304,45 +304,45 @@ bool vtkPiecewisePointHandleItem::MouseMoveEvent(const vtkContextMouseEvent &mou this->GetParent()); if(activeHandle->fDistance<=0 || !parentControl || parentControl->GetCurrentPoint()<0 || !this->GetPiecewiseFunction()) - { + { return false; - } + } vtkIdType curIdx = activeHandle->PointIndex; double point[4]; this->PiecewiseFunction->GetNodeValue(curIdx, point); if(activeHandle->enType==enMidPoint) - { + { double fMid=deltaX/activeHandle->fDistance+activeHandle->fValue; fMid = std::max(fMid, 0.0); fMid = std::min(fMid, 1.0); point[2]=fMid; - } + } else - { + { if(this->MouseOverHandleIndex==2) - { + { deltaY = -deltaY; - } + } double fSharp=deltaY/activeHandle->fDistance+activeHandle->fValue; fSharp = std::max(fSharp, 0.0); fSharp = std::min(fSharp, 1.0); point[3]=fSharp; - } + } this->GetPiecewiseFunction()->SetNodeValue(curIdx, point); return true; - } } + } else if (mouse.GetButton() == vtkContextMouseEvent::NO_BUTTON) - { + { float mspos[2] = { mouse.GetScenePos().GetX(), mouse.GetScenePos().GetY() }; int handleIdx = this->IsOverHandle(mspos); if (this->MouseOverHandleIndex != handleIdx) - { + { this->MouseOverHandleIndex = handleIdx; this->GetScene()->SetDirty(true); return true; - } } + } return false; } @@ -351,9 +351,9 @@ bool vtkPiecewisePointHandleItem::MouseMoveEvent(const vtkContextMouseEvent &mou bool vtkPiecewisePointHandleItem::MouseButtonPressEvent(const vtkContextMouseEvent &) { if(this->MouseOverHandleIndex>=0) - { + { return true; - } + } return false; } @@ -361,11 +361,11 @@ bool vtkPiecewisePointHandleItem::MouseButtonPressEvent(const vtkContextMouseEve bool vtkPiecewisePointHandleItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &) { if(this->MouseOverHandleIndex>=0) - { + { this->MouseOverHandleIndex = -1; this->GetScene()->SetDirty(true); return true; - } + } return false; } @@ -381,28 +381,28 @@ void vtkPiecewisePointHandleItem::SetPiecewiseFunction( vtkPiecewiseFunction* function) { if (function == this->PiecewiseFunction) - { + { return; - } + } if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->RemoveObserver(this->Callback); - } + } this->PiecewiseFunction = function; if (this->PiecewiseFunction) - { + { this->PiecewiseFunction->AddObserver(vtkCommand::ModifiedEvent, this->Callback); this->PiecewiseFunction->AddObserver(vtkCommand::EndEvent, this->Callback); - } + } this->Redraw(); } //----------------------------------------------------------------------------- void vtkPiecewisePointHandleItem::Redraw() { if (this->Scene) - { + { this->Scene->SetDirty(true); - } + } } //----------------------------------------------------------------------------- void vtkPiecewisePointHandleItem::CallRedraw( @@ -412,7 +412,7 @@ void vtkPiecewisePointHandleItem::CallRedraw( vtkPiecewisePointHandleItem* item = reinterpret_cast(receiver); switch(event) - { + { case vtkCommand::ModifiedEvent: case vtkCommand::EndEvent: case vtkControlPointsItem::CurrentPointChangedEvent: @@ -420,7 +420,7 @@ void vtkPiecewisePointHandleItem::CallRedraw( break; default: break; - } + } } //----------------------------------------------------------------------------- @@ -429,14 +429,14 @@ void vtkPiecewisePointHandleItem::PrintSelf(ostream &os, vtkIndent indent) this->Superclass::PrintSelf(os, indent); os << indent << "PiecewiseFunction: "; if (this->PiecewiseFunction) - { + { os << endl; this->PiecewiseFunction->PrintSelf(os, indent.GetNextIndent()); - } + } else - { + { os << "(none)" << endl; - } + } os << indent << "MouseOverHandleIndex: " << this->MouseOverHandleIndex << endl; os << indent << "CurrentPointIndex: " << this->CurrentPointIndex << endl; } diff --git a/Charts/Core/vtkPlot.cxx b/Charts/Core/vtkPlot.cxx index 835f6a5e24e..20b5eac8ece 100644 --- a/Charts/Core/vtkPlot.cxx +++ b/Charts/Core/vtkPlot.cxx @@ -62,10 +62,10 @@ vtkPlot::vtkPlot() : ShiftScale(0.0, 0.0, 1.0, 1.0) vtkPlot::~vtkPlot() { if (this->Selection) - { + { this->Selection->Delete(); this->Selection = NULL; - } + } this->SetLabels(NULL); this->SetXAxis(NULL); this->SetYAxis(NULL); @@ -95,11 +95,11 @@ vtkStdString vtkPlot::GetTooltipLabel(const vtkVector2d &plotPos, // Parse TooltipLabelFormat and build tooltipLabel bool escapeNext = false; for (size_t i = 0; i < format.length(); ++i) - { + { if (escapeNext) - { + { switch (format[i]) - { + { case 'x': tooltipLabel += this->GetNumber(plotPos.GetX(), this->XAxis); break; @@ -110,9 +110,9 @@ vtkStdString vtkPlot::GetTooltipLabel(const vtkVector2d &plotPos, if (this->IndexedLabels && seriesIndex >= 0 && seriesIndex < this->IndexedLabels->GetNumberOfTuples()) - { + { tooltipLabel += this->IndexedLabels->GetValue(seriesIndex); - } + } break; case 'l': // GetLabel() is GetLabel(0) in this implementation @@ -122,21 +122,21 @@ vtkStdString vtkPlot::GetTooltipLabel(const vtkVector2d &plotPos, tooltipLabel += "%"; tooltipLabel += format[i]; break; - } - escapeNext = false; } + escapeNext = false; + } else - { + { if (format[i] == '%') - { + { escapeNext = true; - } + } else - { + { tooltipLabel += format[i]; - } } } + } return tooltipLabel; } @@ -149,24 +149,24 @@ vtkStdString vtkPlot::GetNumber(double position, vtkAxis *axis) ostr.precision(this->GetTooltipPrecision()); if(this->GetTooltipNotation() == vtkAxis::SCIENTIFIC_NOTATION) - { + { ostr.setf(ios::scientific, ios::floatfield); - } + } else if(this->GetTooltipNotation() == vtkAxis::FIXED_NOTATION) - { + { ostr.setf(ios::fixed, ios::floatfield); - } + } if (axis && axis->GetLogScaleActive()) - { + { // If axes are set to logarithmic scale we need to convert the // axis value using 10^(axis value) ostr << pow(double(10.0), double(position)); - } + } else - { + { ostr << position; - } + } return ostr.str(); } @@ -174,9 +174,9 @@ vtkStdString vtkPlot::GetNumber(double position, vtkAxis *axis) bool vtkPlot::SelectPoints(const vtkVector2f&, const vtkVector2f&) { if (this->Selection) - { + { this->Selection->SetNumberOfTuples(0); - } + } return false; } @@ -184,9 +184,9 @@ bool vtkPlot::SelectPoints(const vtkVector2f&, const vtkVector2f&) bool vtkPlot::SelectPointsInPolygon(const vtkContextPolygon &) { if (this->Selection) - { + { this->Selection->SetNumberOfTuples(0); - } + } return false; } @@ -235,10 +235,10 @@ float vtkPlot::GetWidth() void vtkPlot::SetPen(vtkPen *pen) { if (this->Pen != pen) - { + { this->Pen = pen; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -251,10 +251,10 @@ vtkPen* vtkPlot::GetPen() void vtkPlot::SetBrush(vtkBrush *brush) { if (this->Brush != brush) - { + { this->Brush = brush; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -267,10 +267,10 @@ vtkBrush* vtkPlot::GetBrush() void vtkPlot::SetSelectionPen(vtkPen *pen) { if (this->SelectionPen != pen) - { + { this->SelectionPen = pen; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -283,10 +283,10 @@ vtkPen* vtkPlot::GetSelectionPen() void vtkPlot::SetSelectionBrush(vtkBrush *brush) { if (this->SelectionBrush != brush) - { + { this->SelectionBrush = brush; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -313,9 +313,9 @@ vtkStdString vtkPlot::GetLabel() void vtkPlot::SetLabels(vtkStringArray *labels) { if (this->Labels == labels) - { + { return; - } + } this->Labels = labels; this->Modified(); @@ -326,55 +326,55 @@ vtkStringArray * vtkPlot::GetLabels() { // If the label string is empty, return the y column name if (this->Labels) - { + { return this->Labels; - } + } else if (this->AutoLabels) - { + { return this->AutoLabels; - } + } else if (this->Data->GetInput() && this->Data->GetInputArrayToProcess(1, this->Data->GetInput())) - { + { this->AutoLabels = vtkSmartPointer::New(); this->AutoLabels->InsertNextValue(this->Data->GetInputArrayToProcess(1, this->Data->GetInput())->GetName()); return this->AutoLabels; - } + } else - { + { return NULL; - } + } } //----------------------------------------------------------------------------- int vtkPlot::GetNumberOfLabels() { vtkStringArray *labels = this->GetLabels(); if (labels) - { + { return labels->GetNumberOfValues(); - } + } else - { + { return 0; - } + } } //----------------------------------------------------------------------------- void vtkPlot::SetIndexedLabels(vtkStringArray *labels) { if (this->IndexedLabels == labels) - { + { return; - } + } if (labels) - { + { this->TooltipDefaultLabelFormat = "%i: %x, %y"; - } + } else - { + { this->TooltipDefaultLabelFormat = "%l: %x, %y"; - } + } this->IndexedLabels = labels; this->Modified(); @@ -396,9 +396,9 @@ vtkContextMapper2D * vtkPlot::GetData() void vtkPlot::SetTooltipLabelFormat(const vtkStdString &labelFormat) { if (this->TooltipLabelFormat == labelFormat) - { + { return; - } + } this->TooltipLabelFormat = labelFormat; this->Modified(); @@ -441,13 +441,13 @@ vtkStdString vtkPlot::GetLabel(vtkIdType index) { vtkStringArray *labels = this->GetLabels(); if (labels && index >= 0 && index < labels->GetNumberOfValues()) - { + { return labels->GetValue(index); - } + } else - { + { return vtkStdString(); - } + } } //----------------------------------------------------------------------------- void vtkPlot::SetInputData(vtkTable *table) @@ -501,9 +501,9 @@ void vtkPlot::SetInputArray(int index, const vtkStdString &name) void vtkPlot::SetSelection(vtkIdTypeArray *id) { if (!this->GetSelectable()) - { + { return; - } + } vtkSetObjectBodyMacro(Selection,vtkIdTypeArray,id); } @@ -511,10 +511,10 @@ void vtkPlot::SetSelection(vtkIdTypeArray *id) void vtkPlot::SetShiftScale(const vtkRectd &shiftScale) { if (shiftScale != this->ShiftScale) - { + { this->Modified(); this->ShiftScale = shiftScale; - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlot.h b/Charts/Core/vtkPlot.h index fcc8871fc8b..8d2b2ed8eb5 100644 --- a/Charts/Core/vtkPlot.h +++ b/Charts/Core/vtkPlot.h @@ -355,11 +355,11 @@ class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem * The returned \a bounds are stored as (Xmin, Xmax, Ymin, Ymax). */ virtual void GetUnscaledInputBounds(double bounds[4]) - { + { // Implemented here by calling GetBounds() to support plot // subclasses that do no log-scaling or plot orientation. return this->GetBounds(bounds); - } + } /** * Subclasses that build data caches to speed up painting should override this diff --git a/Charts/Core/vtkPlot3D.cxx b/Charts/Core/vtkPlot3D.cxx index 862b12cb449..434b729f917 100644 --- a/Charts/Core/vtkPlot3D.cxx +++ b/Charts/Core/vtkPlot3D.cxx @@ -32,9 +32,9 @@ template void CopyToPoints(float *data, A *input, size_t offset, size_t n) { for (size_t i = 0; i < n; ++i) - { + { data[3 * i + offset] = *(input++); - } + } } } @@ -66,10 +66,10 @@ void vtkPlot3D::PrintSelf(ostream &os, vtkIndent indent) void vtkPlot3D::SetPen(vtkPen *pen) { if (this->Pen != pen) - { + { this->Pen = pen; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -82,10 +82,10 @@ vtkPen* vtkPlot3D::GetSelectionPen() void vtkPlot3D::SetSelectionPen(vtkPen *pen) { if (this->SelectionPen != pen) - { + { this->SelectionPen = pen; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -152,23 +152,23 @@ void vtkPlot3D::SetInputData(vtkTable *input, const vtkStdString &xName, float *data = this->Points[0].GetData(); switch(xArr->GetDataType()) - { + { vtkTemplateMacro(CopyToPoints(data, static_cast(xArr->GetVoidPointer(0)), 0, n)); - } + } switch(yArr->GetDataType()) - { + { vtkTemplateMacro(CopyToPoints(data, static_cast(yArr->GetVoidPointer(0)), 1, n)); - } + } switch(zArr->GetDataType()) - { + { vtkTemplateMacro(CopyToPoints(data, static_cast(zArr->GetVoidPointer(0)), 2, n)); - } + } this->PointsBuildTime.Modified(); // This removes the colors from our points. @@ -208,17 +208,17 @@ void vtkPlot3D::SetColors(vtkDataArray *colorArr) double max = VTK_DOUBLE_MIN; for (unsigned int i = 0; i < this->Points.size(); ++i) - { + { double value = colorArr->GetComponent(i, 0); if (value > max) - { + { max = value; - } + } if (value < min) - { + { min = value; - } } + } lookupTable->SetNumberOfTableValues(256); lookupTable->SetRange(min, max); @@ -226,14 +226,14 @@ void vtkPlot3D::SetColors(vtkDataArray *colorArr) this->Colors->Reset(); for (unsigned int i = 0; i < this->Points.size(); ++i) - { + { double value = colorArr->GetComponent(i, 0); unsigned char *rgb = lookupTable->MapValue(value); const unsigned char constRGB[3] = { rgb[0], rgb[1], rgb[2] }; this->Colors->InsertNextTypedTuple(&constRGB[0]); this->Colors->InsertNextTypedTuple(&constRGB[1]); this->Colors->InsertNextTypedTuple(&constRGB[2]); - } + } this->Modified(); } @@ -249,33 +249,33 @@ void vtkPlot3D::ComputeDataBounds() double zMax = VTK_DOUBLE_MIN; for (unsigned int i = 0; i < this->Points.size(); ++i) - { + { float *point = this->Points[i].GetData(); if (point[0] < xMin) - { + { xMin = point[0]; - } + } if (point[0] > xMax) - { + { xMax = point[0]; - } + } if (point[1] < yMin) - { + { yMin = point[1]; - } + } if (point[1] > yMax) - { + { yMax = point[1]; - } + } if (point[2] < zMin) - { + { zMin = point[2]; - } + } if (point[2] > zMax) - { + { zMax = point[2]; - } } + } this->DataBounds.clear(); this->DataBounds.resize(8); @@ -350,9 +350,9 @@ std::string vtkPlot3D::GetZAxisLabel() void vtkPlot3D::SetSelection(vtkIdTypeArray *id) { if (id == this->Selection) - { + { return; - } + } this->Selection = id; this->Modified(); } diff --git a/Charts/Core/vtkPlotArea.cxx b/Charts/Core/vtkPlotArea.cxx index 0acc625ebeb..87ab7a8a95e 100644 --- a/Charts/Core/vtkPlotArea.cxx +++ b/Charts/Core/vtkPlotArea.cxx @@ -39,10 +39,10 @@ namespace { inline bool vtkIsBadPoint(const vtkVector2f& vec) - { + { return (vtkMath::IsNan(vec.GetX()) || vtkMath::IsInf(vec.GetX()) || vtkMath::IsNan(vec.GetY()) || vtkMath::IsInf(vec.GetY())); - } + } } // end of namespace // Keeps all data-dependent meta-data that's updated in @@ -51,57 +51,57 @@ class vtkPlotArea::vtkTableCache { // PIMPL for STL vector... struct vtkIndexedVector2f - { + { size_t index; vtkVector2f pos; static bool compVector3fX( const vtkIndexedVector2f& v1, const vtkIndexedVector2f& v2) - { + { if (v1.pos.GetX() < v2.pos.GetX()) - { + { return true; - } + } else - { + { return false; - } } + } // See if the point is within tolerance. static bool inRange(const vtkVector2f& point, const vtkVector2f& tol, const vtkVector2f& current) - { + { if (current.GetX() > point.GetX() - tol.GetX() && current.GetX() < point.GetX() + tol.GetX() && current.GetY() > point.GetY() - tol.GetY() && current.GetY() < point.GetY() + tol.GetY()) - { + { return true; - } + } else - { + { return false; - } } - }; + } + }; // DataStructure used to store sorted points. class VectorPIMPL : public std::vector { public: void Initialize(vtkVector2f* array, size_t n) - { + { this->reserve(n); for (size_t i = 0; i < n; ++i) - { + { vtkIndexedVector2f tmp; tmp.index = i; tmp.pos = array[i]; this->push_back(tmp); - } } + } //----------------------------------------------------------------------------- vtkIdType GetNearestPoint( const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location) - { + { // Set up our search array, use the STL lower_bound algorithm VectorPIMPL::iterator low; VectorPIMPL &v = *this; @@ -115,20 +115,20 @@ class vtkPlotArea::vtkTableCache // Now consider the y axis float highX = point.GetX() + tol.GetX(); while (low != v.end()) - { + { if (vtkIndexedVector2f::inRange(point, tol, (*low).pos)) - { + { *location = (*low).pos; return static_cast((*low).index); - } + } else if (low->pos.GetX() > highX) - { + { break; - } - ++low; } - return -1; + ++low; } + return -1; + } }; private: vtkTimeStamp DataMTime; @@ -144,7 +144,7 @@ class vtkPlotArea::vtkTableCache assert(array); if (this->ValidPointMask) - { + { assert(array->GetNumberOfTuples() == this->ValidPointMask->GetNumberOfTuples()); assert(array->GetNumberOfComponents() == this->ValidPointMask->GetNumberOfComponents()); @@ -155,30 +155,30 @@ class vtkPlotArea::vtkTableCache ComputeArrayRange worker; if (!dispatcher.Execute(array, this->ValidPointMask, worker)) - { + { vtkGenericWarningMacro( <<"Error computing range. Unsupported array type: " << array->GetClassName() << " (" << array->GetDataTypeAsString() << ")."); - } + } return worker.Result; - } + } else - { + { vtkArrayDispatch::Dispatch dispatcher; ComputeArrayRange worker; if (!dispatcher.Execute(array, worker)) - { + { vtkGenericWarningMacro( <<"Error computing range. Unsupported array type: " << array->GetClassName() << " (" << array->GetDataTypeAsString() << ")."); - } + } return worker.Result; - } + } } @@ -200,18 +200,18 @@ class vtkPlotArea::vtkTableCache int numComps = array->GetNumberOfComponents(); for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx) - { + { for (int compIdx = 0; compIdx < numComps; ++compIdx) - { + { if (mask->GetTypedComponent(tupleIdx, compIdx) != 0) - { + { typename ArrayT::ValueType val = array->GetTypedComponent(tupleIdx, compIdx); Result[0] = std::min(Result[0], static_cast(val)); Result[1] = std::max(Result[1], static_cast(val)); - } } } + } } // No mask: @@ -222,15 +222,15 @@ class vtkPlotArea::vtkTableCache int numComps = array->GetNumberOfComponents(); for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx) - { + { for (int compIdx = 0; compIdx < numComps; ++compIdx) - { + { typename ArrayT::ValueType val = array->GetTypedComponent(tupleIdx, compIdx); Result[0] = std::min(Result[0], static_cast(val)); Result[1] = std::max(Result[1], static_cast(val)); - } } + } } }; @@ -259,53 +259,53 @@ class vtkPlotArea::vtkTableCache void operator()(ArrayT *array) { if (this->UseLog) - { + { float *data = this->Data; for (vtkIdType valIdx = 0; valIdx < this->NumValues; ++valIdx, data += this->DataIncrement) - { + { *data = log10(static_cast( (array->GetValue(valIdx) + this->Transform[0]) * this->Transform[1])); - } } + } else - { + { float *data = this->Data; for (vtkIdType valIdx = 0; valIdx < this->NumValues; ++valIdx, data += this->DataIncrement) - { + { *data = static_cast( (array->GetValue(valIdx) + this->Transform[0]) * this->Transform[1]); - } } } + } // No array, just iterate to number of values void operator()() { if (this->UseLog) - { + { float *data = this->Data; for (vtkIdType valIdx = 0; valIdx < this->NumValues; ++valIdx, data += this->DataIncrement) - { + { *data = log10(static_cast((valIdx + this->Transform[0]) * this->Transform[1])); - } } + } else - { + { float *data = this->Data; for (vtkIdType valIdx = 0; valIdx < this->NumValues; ++valIdx, data += this->DataIncrement) - { + { *data = static_cast((valIdx + this->Transform[0]) * this->Transform[1]); - } } } + } }; VectorPIMPL SortedPoints; @@ -326,29 +326,29 @@ class vtkPlotArea::vtkTableCache vtkTableCache() - { + { this->Reset(); - } + } void Reset() - { + { this->ValidPointMask = NULL; this->Points->Initialize(); this->Points->SetDataTypeToFloat(); this->BadPoints.clear(); - } + } bool IsInputDataValid() const - { + { return this->InputArrays[1] != NULL && this->InputArrays[2] != NULL; - } + } bool SetPoints(vtkDataArray* x, vtkDataArray* y1, vtkDataArray* y2) - { + { if (y1 == NULL || y2 == NULL) - { + { return false; - } + } vtkIdType numTuples = y1->GetNumberOfTuples(); @@ -362,21 +362,21 @@ class vtkPlotArea::vtkTableCache this->SortedPoints.clear(); this->DataMTime.Modified(); return true; - } + } void GetDataBounds(double bounds[4]) - { + { if (this->DataMTime > this->BoundsMTime) - { + { vtkTuple rangeX, rangeY1, rangeY2; if (this->InputArrays[0]) - { + { rangeX = this->GetDataRange(this->InputArrays[0]); - } + } else - { + { rangeX[0] = 0; rangeX[1] = (this->Points->GetNumberOfPoints()/2-1); - } + } rangeY1 = this->GetDataRange(this->InputArrays[1]); rangeY2 = this->GetDataRange(this->InputArrays[2]); @@ -384,14 +384,14 @@ class vtkPlotArea::vtkTableCache this->DataBounds.SetMinPoint(rangeX[0], std::min(rangeY1[0], rangeY2[0]), 0); this->DataBounds.SetMaxPoint(rangeX[1], std::max(rangeY1[1], rangeY2[1]), 0); this->BoundsMTime.Modified(); - } + } double bds[6]; this->DataBounds.GetBounds(bds); std::copy(bds, bds+4, bounds); - } + } void UpdateCache(vtkPlotArea* self) - { + { const vtkRectd& ss = self->GetShiftScale(); vtkAxis* xaxis = self->GetXAxis(); vtkAxis* yaxis = self->GetYAxis(); @@ -400,10 +400,10 @@ class vtkPlotArea::vtkTableCache this->Points->GetMTime() > xaxis->GetMTime() && this->Points->GetMTime() > yaxis->GetMTime() && ss == this->ShiftScale) - { + { // nothing to do. return; - } + } vtkTuple useLog; useLog[0] = xaxis->GetLogScaleActive(); @@ -414,7 +414,7 @@ class vtkPlotArea::vtkTableCache float* data = reinterpret_cast(this->Points->GetVoidPointer(0)); if (this->InputArrays[0]) - { + { vtkDataArray *array = this->InputArrays[0].GetPointer(); vtkIdType numValues = array->GetNumberOfTuples() * array->GetNumberOfComponents(); @@ -428,14 +428,14 @@ class vtkPlotArea::vtkTableCache if (!dispatcher.Execute(array, worker1) || !dispatcher.Execute(array, worker2)) - { + { vtkGenericWarningMacro("Error creating points, unsupported array type: " << array->GetClassName() << " (" << array->GetDataTypeAsString() << ")."); - } } + } else - { + { CopyToPoints worker1(data, 4, numTuples, vtkVector2d(ss[0], ss[2]), useLog[0]); CopyToPoints worker2(&data[2], 4, numTuples, vtkVector2d(ss[0], ss[2]), @@ -443,7 +443,7 @@ class vtkPlotArea::vtkTableCache // No array, no need to dispatch: worker1(); worker2(); - } + } vtkDataArray *array1 = this->InputArrays[1].GetPointer(); vtkDataArray *array2 = this->InputArrays[2].GetPointer(); @@ -461,49 +461,49 @@ class vtkPlotArea::vtkTableCache if (!dispatcher.Execute(array1, worker1) || !dispatcher.Execute(array2, worker2)) - { + { vtkGenericWarningMacro("Error creating points: Array dispatch failed."); - } + } // Set the bad-points mask. vtkVector2f* vec2f = reinterpret_cast(this->Points->GetVoidPointer(0)); for (vtkIdType cc=0; cc < numTuples; cc++) - { + { bool is_bad = (this->ValidPointMask && this->ValidPointMask->GetValue(cc) == 0); is_bad = is_bad || vtkIsBadPoint(vec2f[2*cc]); is_bad = is_bad || vtkIsBadPoint(vec2f[2*cc + 1]); if (is_bad) - { + { // this ensures that the GetNearestPoint() fails for masked out points. vec2f[2*cc] = vtkVector2f(vtkMath::Nan(), vtkMath::Nan()); vec2f[2*cc + 1] = vtkVector2f(vtkMath::Nan(), vtkMath::Nan()); this->BadPoints.push_back(cc); - } } + } this->ShiftScale = ss; this->Points->Modified(); this->SortedPoints.clear(); - } + } vtkIdType GetNearestPoint( const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location) - { + { if (this->Points->GetNumberOfPoints() == 0) - { + { return -1; - } + } if (this->SortedPoints.size() == 0) - { + { float* data = reinterpret_cast(this->Points->GetVoidPointer(0)); this->SortedPoints.Initialize(reinterpret_cast(data), this->Points->GetNumberOfPoints()); std::sort(this->SortedPoints.begin(), this->SortedPoints.end(), vtkIndexedVector2f::compVector3fX); - } - return this->SortedPoints.GetNearestPoint(point, tol, location); } + return this->SortedPoints.GetNearestPoint(point, tol, location); + } }; vtkStandardNewMacro(vtkPlotArea); @@ -525,22 +525,22 @@ vtkPlotArea::~vtkPlotArea() void vtkPlotArea::Update() { if (!this->Visible) - { + { return; - } + } vtkTable* table = this->GetInput(); if (!table) - { + { vtkDebugMacro("Update event called with no input table set."); this->TableCache->Reset(); return; - } + } if (this->Data->GetMTime() > this->UpdateTime || table->GetMTime() > this->UpdateTime || this->GetMTime() > this->UpdateTime) - { + { vtkTableCache& cache = (*this->TableCache); cache.Reset(); @@ -551,7 +551,7 @@ void vtkPlotArea::Update() this->Data->GetInputArrayToProcess(1, table), this->Data->GetInputArrayToProcess(2, table)); this->UpdateTime.Modified(); - } + } } //---------------------------------------------------------------------------- @@ -559,9 +559,9 @@ void vtkPlotArea::UpdateCache() { vtkTableCache& cache = (*this->TableCache); if (!this->Visible || !cache.IsInputDataValid()) - { + { return; - } + } cache.UpdateCache(this); } @@ -570,9 +570,9 @@ void vtkPlotArea::GetBounds(double bounds[4]) { vtkTableCache& cache = (*this->TableCache); if (!this->Visible || !cache.IsInputDataValid()) - { + { return; - } + } cache.GetDataBounds(bounds); } @@ -581,31 +581,31 @@ bool vtkPlotArea::Paint(vtkContext2D *painter) { vtkTableCache& cache = (*this->TableCache); if (!this->Visible || !cache.IsInputDataValid() || cache.Points->GetNumberOfPoints() == 0) - { + { return false; - } + } painter->ApplyPen(this->Pen); painter->ApplyBrush(this->Brush); vtkIdType start = 0; for (std::vector::iterator iter = cache.BadPoints.begin(); iter != cache.BadPoints.end(); ++iter) - { + { vtkIdType end = *iter; if ((end-start) >= 2) - { + { painter->DrawQuadStrip( reinterpret_cast(cache.Points->GetVoidPointer(2*2*start)), (end-start)*2); - } - start = end; } + start = end; + } if (cache.Points->GetNumberOfPoints() - (2*start) > 4) - { + { painter->DrawQuadStrip( reinterpret_cast(cache.Points->GetVoidPointer(2*2*start)), cache.Points->GetNumberOfPoints() - (2*start)); - } + } return true; } @@ -625,9 +625,9 @@ vtkIdType vtkPlotArea::GetNearestPoint( { vtkTableCache& cache = (*this->TableCache); if (!this->Visible || !cache.IsInputDataValid() || cache.Points->GetNumberOfPoints() == 0) - { + { return -1; - } + } return cache.GetNearestPoint(point, tolerance, location); } @@ -648,11 +648,11 @@ vtkStdString vtkPlotArea::GetTooltipLabel(const vtkVector2d &plotPos, // Parse TooltipLabelFormat and build tooltipLabel bool escapeNext = false; for (size_t i = 0; i < format.length(); ++i) - { + { if (escapeNext) - { + { switch (format[i]) - { + { case 'a': tooltipLabel += this->GetNumber(data[idx].GetY(), this->YAxis); break; @@ -663,21 +663,21 @@ vtkStdString vtkPlotArea::GetTooltipLabel(const vtkVector2d &plotPos, tooltipLabel += "%"; tooltipLabel += format[i]; break; - } - escapeNext = false; } + escapeNext = false; + } else - { + { if (format[i] == '%') - { + { escapeNext = true; - } + } else - { + { tooltipLabel += format[i]; - } } } + } return tooltipLabel; } diff --git a/Charts/Core/vtkPlotBag.cxx b/Charts/Core/vtkPlotBag.cxx index cfb0fdb8f58..42d4d70534c 100644 --- a/Charts/Core/vtkPlotBag.cxx +++ b/Charts/Core/vtkPlotBag.cxx @@ -57,39 +57,39 @@ vtkPlotBag::vtkPlotBag() vtkPlotBag::~vtkPlotBag() { if (this->MedianPoints) - { + { this->MedianPoints->Delete(); this->MedianPoints = 0; - } + } if (this->Q3Points) - { + { this->Q3Points->Delete(); this->Q3Points = 0; - } + } if (this->LinePen) - { + { this->LinePen->Delete(); this->LinePen = 0; - } + } } //----------------------------------------------------------------------------- void vtkPlotBag::Update() { if (!this->Visible) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); vtkDataArray *density = vtkArrayDownCast( this->Data->GetInputAbstractArrayToProcess(2, this->GetInput())); if (!table || !density) - { + { vtkDebugMacro(<< "Update event called with no input table or density column set."); return; - } + } bool update = (this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || this->MTime > this->BuildTime); @@ -97,10 +97,10 @@ void vtkPlotBag::Update() this->Superclass::Update(); if (update) - { + { vtkDebugMacro(<< "Updating cached values."); this->UpdateTableCache(density); - } + } } //----------------------------------------------------------------------------- @@ -123,9 +123,9 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density) this->Q3Points->Reset(); if (!this->Points) - { + { return; - } + } vtkDataArray* d = density; vtkPoints2D* points = this->Points; @@ -135,9 +135,9 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density) std::vector ids; ids.reserve(nbPoints); for (int i = 0; i < nbPoints; i++) - { + { ids.push_back(DensityVal(d->GetTuple1(i), i)); - } + } std::sort(ids.begin(), ids.end()); vtkNew q3Points; @@ -148,34 +148,34 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density) // Compute total density sum double densitySum = 0.0; for (vtkIdType i = 0; i < nbPoints; i++) - { + { densitySum += d->GetTuple1(i); - } + } double sum = 0.0; for (vtkIdType i = 0; i < nbPoints; i++) - { + { double x[3]; points->GetPoint(ids[i].Id, x); sum += ids[i].Density; if (sum < 0.5 * densitySum) - { + { medianPoints->InsertNextPoint(x); - } + } if (sum < 0.99 * densitySum) - { + { q3Points->InsertNextPoint(x); - } + } else - { + { break; - } } + } // Compute the convex hull for the median points vtkIdType nbMedPoints = medianPoints->GetNumberOfPoints(); if (nbMedPoints > 2) - { + { int size = medianPoints->GetSizeCCWHullZ(); this->MedianPoints->SetDataTypeToFloat(); this->MedianPoints->SetNumberOfPoints(size+1); @@ -184,22 +184,22 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density) double x[3]; this->MedianPoints->GetPoint(0, x); this->MedianPoints->SetPoint(size, x); - } + } else if (nbMedPoints > 0) - { + { this->MedianPoints->SetNumberOfPoints(nbMedPoints); for (int j = 0; j < nbMedPoints; j++) - { + { double x[3]; medianPoints->GetPoint(j, x); this->MedianPoints->SetPoint(j, x); - } } + } // Compute the convex hull for the first quartile points vtkIdType nbQ3Points = q3Points->GetNumberOfPoints(); if (nbQ3Points > 2) - { + { int size = q3Points->GetSizeCCWHullZ(); this->Q3Points->SetDataTypeToFloat(); this->Q3Points->SetNumberOfPoints(size+1); @@ -208,17 +208,17 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density) double x[3]; this->Q3Points->GetPoint(0, x); this->Q3Points->SetPoint(size, x); - } + } else if (nbQ3Points > 0) - { + { this->Q3Points->SetNumberOfPoints(nbQ3Points); for (int j = 0; j < nbQ3Points; j++) - { + { double x[3]; q3Points->GetPoint(j, x); this->Q3Points->SetPoint(j, x); - } } + } this->BuildTime.Modified(); } @@ -231,12 +231,12 @@ bool vtkPlotBag::Paint(vtkContext2D *painter) vtkTable *table = this->Data->GetInput(); if (!this->Visible || !this->Points || !table) - { + { return false; - } + } if (this->BagVisible) - { + { unsigned char bcolor[4]; this->Brush->GetColor(bcolor); @@ -246,27 +246,27 @@ bool vtkPlotBag::Paint(vtkContext2D *painter) painter->ApplyPen(this->LinePen); painter->ApplyBrush(this->Brush); if (this->Q3Points->GetNumberOfPoints() > 2) - { + { painter->DrawPolygon(this->Q3Points); - } + } else if (this->Q3Points->GetNumberOfPoints() == 2) - { + { painter->DrawLine(this->Q3Points); - } + } this->Brush->SetColor(bcolor); this->Brush->SetOpacity(128); painter->ApplyBrush(this->Brush); if (this->MedianPoints->GetNumberOfPoints() > 2) - { + { painter->DrawPolygon(this->MedianPoints); - } + } else if (this->MedianPoints->GetNumberOfPoints() == 2) - { + { painter->DrawLine(this->MedianPoints); - } } + } painter->ApplyPen(this->Pen); @@ -301,24 +301,24 @@ vtkStringArray* vtkPlotBag::GetLabels() { // If the label string is empty, return the y column name if (this->Labels) - { + { return this->Labels; - } + } else if (this->AutoLabels) - { + { return this->AutoLabels; - } + } else if (this->Data->GetInput()) - { + { this->AutoLabels = vtkSmartPointer::New(); vtkDataArray *density = vtkArrayDownCast( this->Data->GetInputAbstractArrayToProcess(2, this->GetInput())); if (density) - { + { this->AutoLabels->InsertNextValue(density->GetName()); - } - return this->AutoLabels; } + return this->AutoLabels; + } return NULL; } @@ -335,11 +335,11 @@ vtkStdString vtkPlotBag::GetTooltipLabel(const vtkVector2d &plotPos, vtkDataArray *density = vtkArrayDownCast( this->Data->GetInputAbstractArrayToProcess(2, this->GetInput())); for (size_t i = 0; i < format.length(); ++i) - { + { if (escapeNext) - { + { switch (format[i]) - { + { case 'x': tooltipLabel += this->GetNumber(plotPos.GetX(), this->XAxis); break; @@ -355,56 +355,56 @@ vtkStdString vtkPlotBag::GetTooltipLabel(const vtkVector2d &plotPos, if (this->IndexedLabels && seriesIndex >= 0 && seriesIndex < this->IndexedLabels->GetNumberOfTuples()) - { + { tooltipLabel += this->IndexedLabels->GetValue(seriesIndex); - } + } break; case 'l': // GetLabel() is GetLabel(0) in this implementation tooltipLabel += this->GetLabel(); break; case 'c': - { + { std::stringstream ss; ss << seriesIndex; tooltipLabel += ss.str(); - } + } break; case 'C': - { + { vtkAbstractArray *colName = vtkArrayDownCast( this->GetInput()->GetColumnByName("ColName")); std::stringstream ss; if (colName) - { + { ss << colName->GetVariantValue(seriesIndex).ToString(); - } + } else - { + { ss << "?"; - } - tooltipLabel += ss.str(); } + tooltipLabel += ss.str(); + } break; default: // If no match, insert the entire format tag tooltipLabel += "%"; tooltipLabel += format[i]; break; - } - escapeNext = false; } + escapeNext = false; + } else - { + { if (format[i] == '%') - { + { escapeNext = true; - } + } else - { + { tooltipLabel += format[i]; - } } } + } return tooltipLabel; } @@ -424,10 +424,10 @@ void vtkPlotBag::SetInputData(vtkTable *table, const vtkStdString &yColumn, if (table->GetColumnByName(densityColumn.c_str())->GetNumberOfTuples() != table->GetColumnByName(yColumn.c_str())->GetNumberOfTuples()) - { + { vtkErrorMacro(<< "Input table not correctly initialized!"); return; - } + } this->SetInputData(table, yColumn, yColumn, densityColumn); this->UseIndexForXSeries = true; @@ -452,9 +452,9 @@ void vtkPlotBag::SetInputData(vtkTable *table, const vtkStdString &xColumn, this->Data->SetInputArrayToProcess(2, 0, 0, vtkDataObject::FIELD_ASSOCIATION_ROWS, densityColumn.c_str()); if (this->AutoLabels) - { + { this->AutoLabels = 0; - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlotBar.cxx b/Charts/Core/vtkPlotBar.cxx index 4a9a999f61f..d5649d28ba2 100644 --- a/Charts/Core/vtkPlotBar.cxx +++ b/Charts/Core/vtkPlotBar.cxx @@ -54,16 +54,16 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, B *b, float* data = static_cast(points->GetVoidPointer(0)); float* prevData = NULL; if (previousPoints && static_cast(previousPoints->GetNumberOfPoints()) == n) - { + { prevData = static_cast(previousPoints->GetVoidPointer(0)); - } + } float prev = 0.0; for (int i = 0; i < n; ++i) - { + { if (prevData) - { + { prev = prevData[2 * i + 1]; - } + } A tmpA(static_cast((a[i] + ss[0]) * ss[2])); B tmpB(static_cast((b[i] + ss[1]) * ss[3])); data[2 * i] = static_cast((logScale & 1) ? @@ -72,7 +72,7 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, B *b, data[2 * i + 1] = static_cast((logScale & 2) ? log10(static_cast(tmpB + prev)) : (tmpB + prev)); - } + } } // Copy one array into the points array, use the index of that array as x @@ -84,16 +84,16 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, int n, float* data = static_cast(points->GetVoidPointer(0)); float* prevData = NULL; if (previousPoints && static_cast(previousPoints->GetNumberOfPoints()) == n) - { + { prevData = static_cast(previousPoints->GetVoidPointer(0)); - } + } float prev = 0.0; for (int i = 0; i < n; ++i) - { + { if (prevData) - { + { prev = prevData[2 * i + 1]; - } + } A tmpA(static_cast((a[i] + ss[1]) * ss[3])); data[2 * i] = static_cast((logScale & 1) ? log10(static_cast(i + 1.0)) @@ -101,7 +101,7 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, int n, data[2 * i + 1] = static_cast((logScale & 2) ? log10(static_cast(tmpA + prev)) : (tmpA + prev)); - } + } } // Copy the two arrays into the points array @@ -111,12 +111,12 @@ void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previousPoints, A *a, const vtkRectd &ss) { switch(b->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints(points,previousPoints, a, static_cast(b->GetVoidPointer(0)), n, logScale, ss)); - } + } } } // namespace @@ -129,60 +129,60 @@ class vtkPlotBarSegment : public vtkObject { static vtkPlotBarSegment *New(); vtkPlotBarSegment() - { + { this->Bar = NULL; this->Points = NULL; this->Sorted = NULL; this->Previous = NULL; this->Colors = NULL; - } + } ~vtkPlotBarSegment() VTK_OVERRIDE - { + { delete this->Sorted; - } + } void Configure(vtkPlotBar* bar, vtkDataArray* xArray, vtkDataArray* yArray, vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment* prev) - { + { this->Bar = bar; this->Previous = prev; if (!this->Points) - { + { this->Points = vtkSmartPointer::New(); - } + } // For the atypical case that Configure is called on a non-fresh "this" delete this->Sorted; int logScale = (xAxis->GetLogScaleActive() ? 1 : 0) + (yAxis->GetLogScaleActive() ? 2 : 0); if (xArray) - { + { switch (xArray->GetDataType()) - { + { vtkTemplateMacro( CopyToPointsSwitch(this->Points,this->Previous ? this->Previous->Points : 0, static_cast(xArray->GetVoidPointer(0)), yArray, xArray->GetNumberOfTuples(), logScale, this->Bar->GetShiftScale())); - } } + } else - { // Using Index for X Series + { // Using Index for X Series switch (yArray->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints(this->Points, this->Previous ? this->Previous->Points : 0, static_cast(yArray->GetVoidPointer(0)), yArray->GetNumberOfTuples(), logScale, this->Bar->GetShiftScale())); - } } } + } void Paint(vtkContext2D *painter, vtkPen *pen, vtkBrush *brush, float width, float offset, int orientation) - { + { painter->ApplyPen(pen); painter->ApplyBrush(brush); int n = this->Points->GetNumberOfPoints(); @@ -190,90 +190,90 @@ class vtkPlotBarSegment : public vtkObject { vtkArrayDownCast(this->Points->GetData())->GetPointer(0); float *p = NULL; if (this->Previous) - { + { p = vtkArrayDownCast( this->Previous->Points->GetData())->GetPointer(0); - } + } for (int i = 0; i < n; ++i) - { + { if (this->Colors) - { + { painter->GetBrush()->SetColor(vtkColor4ub(this->Colors->GetPointer(i * 4))); - } + } if (orientation == vtkPlotBar::VERTICAL) - { + { if (p) - { + { painter->DrawRect(f[2 * i] - (width / 2) - offset, p[2 * i + 1], width, f[2 * i + 1] - p[2 * i + 1]); - } + } else - { + { painter->DrawRect(f[2 * i] - (width / 2) - offset, 0.0, width, f[2 * i + 1]); - } } + } else // HORIZONTAL orientation - { + { if (p) - { + { painter->DrawRect(p[2 * i + 1], f[2 * i] - (width / 2) - offset, f[2 * i + 1] - p[2 * i + 1], width); - } + } else - { + { painter->DrawRect(0.0, f[2 * i] - (width / 2) - offset, f[2 * i + 1], width); - } } } + } // Paint selections if there are any. vtkIdTypeArray *selection = this->Bar->GetSelection(); if (!selection) - { + { return; - } + } painter->ApplyBrush(this->Bar->GetSelectionBrush()); for (vtkIdType j = 0; j < selection->GetNumberOfTuples(); ++j) - { + { int i = selection->GetValue(j); if (orientation == vtkPlotBar::VERTICAL) - { + { if (p) - { + { painter->DrawRect(f[2 * i] - (width / 2) - offset, p[2 * i + 1], width, f[2 * i + 1] - p[2 * i + 1]); - } + } else - { + { painter->DrawRect(f[2 * i] - (width / 2) - offset, 0.0, width, f[2 * i + 1]); - } } + } else // HORIZONTAL orientation - { + { if (p) - { + { painter->DrawRect(p[2 * i + 1], f[2 * i] - (width / 2) - offset, f[2 * i + 1] - p[2 * i + 1], width); - } + } else - { + { painter->DrawRect(0.0, f[2 * i] - (width / 2) - offset, f[2 * i + 1], width); - } } } } + } vtkIdType GetNearestPoint(const vtkVector2f& point, vtkVector2f* location, float width, float offset, int orientation) - { + { if (!this->Points && this->Points->GetNumberOfPoints()) - { + { return -1; - } + } // The extent of any given bar is half a width on either // side of the point with which it is associated. @@ -286,9 +286,9 @@ class vtkPlotBarSegment : public vtkObject { // X and Y of all the other references to the bar data. vtkVector2f targetPoint(point); if (orientation == vtkPlotBar::HORIZONTAL) - { + { targetPoint.Set(point.GetY(), point.GetX()); // Swap x and y - } + } this->CreateSortedPoints(); @@ -303,49 +303,49 @@ class vtkPlotBarSegment : public vtkObject { low = std::lower_bound(v.begin(), v.end(), lowPoint); while (low != v.end()) - { + { // Does the bar surround the point? if (low->pos.GetX()-halfWidth-offset < targetPoint.GetX() && low->pos.GetX()+halfWidth-offset > targetPoint.GetX()) - { + { // Is the point within the vertical extent of the bar? if ((targetPoint.GetY() >= 0 && targetPoint.GetY() < low->pos.GetY()) || (targetPoint.GetY() < 0 && targetPoint.GetY() > low->pos.GetY())) - { + { *location = low->pos; return low->index; - } } + } // Is the left side of the bar beyond the point? if (low->pos.GetX()-offset-halfWidth > targetPoint.GetX()) - { + { break; - } - ++low; } - return -1; + ++low; } + return -1; + } void CreateSortedPoints() { // Sorted points, used when searching for the nearest point. if (!this->Sorted) - { + { vtkIdType n = this->Points->GetNumberOfPoints(); vtkVector2f* data = static_cast(this->Points->GetVoidPointer(0)); this->Sorted = new VectorPIMPL(data, n); std::sort(this->Sorted->begin(), this->Sorted->end()); - } + } } bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max, float width, float offset, int orientation) { if (!this->Points) - { + { return false; - } + } this->CreateSortedPoints(); @@ -354,10 +354,10 @@ class vtkPlotBarSegment : public vtkObject { vtkVector2f targetMin(min); vtkVector2f targetMax(max); if (orientation == vtkPlotBar::HORIZONTAL) - { + { targetMin.Set(min.GetY(), min.GetX()); targetMax.Set(max.GetY(), max.GetX()); - } + } // The extent of any given bar is half a width on either // side of the point with which it is associated. @@ -376,44 +376,44 @@ class vtkPlotBarSegment : public vtkObject { std::vector selected; while (low != v.end()) - { + { // Is the bar's X coordinates at least partially within the box? if (low->pos.GetX()+halfWidth-offset > targetMin.GetX() && low->pos.GetX()-halfWidth-offset < targetMax.GetX()) - { + { // Is the bar within the vertical extent of the box? if ((targetMin.GetY() > 0 && low->pos.GetY() >= targetMin.GetY()) || (targetMax.GetY() < 0 && low->pos.GetY() <= targetMax.GetY()) || (targetMin.GetY() < 0 && targetMax.GetY() > 0)) - { + { selected.push_back(low->index); - } } + } // Is the left side of the bar beyond the box? if (low->pos.GetX()-offset-halfWidth > targetMax.GetX()) - { + { break; - } - ++low; } + ++low; + } if (selected.empty()) - { + { return false; - } + } else - { + { this->Bar->GetSelection()->SetNumberOfTuples(selected.size()); vtkIdType *ptr = static_cast(this->Bar->GetSelection()->GetVoidPointer(0)); for (size_t i = 0; i < selected.size(); ++i) - { + { ptr[i] = selected[i]; - } + } this->Bar->GetSelection()->Modified(); return true; - } } + } // Indexed vector for sorting struct vtkIndexedVector2f @@ -423,9 +423,9 @@ class vtkPlotBarSegment : public vtkObject { // Compare two vtkIndexedVector2f, in X component only bool operator<(const vtkIndexedVector2f& v2) const - { + { return (this->pos.GetX() < v2.pos.GetX()); - } + } }; class VectorPIMPL : public std::vector @@ -436,12 +436,12 @@ class vtkPlotBarSegment : public vtkObject { { this->reserve(n); for (size_t i = 0; i < n; ++i) - { + { vtkIndexedVector2f tmp; tmp.index = i; tmp.pos = array[i]; this->push_back(tmp); - } + } } }; @@ -451,7 +451,7 @@ class vtkPlotBarSegment : public vtkObject { VectorPIMPL* Sorted; vtkVector2d ScalingFactor; vtkUnsignedCharArray *Colors; - }; +}; vtkStandardNewMacro(vtkPlotBarSegment); @@ -461,72 +461,72 @@ class vtkPlotBarPrivate vtkPlotBarPrivate(vtkPlotBar *bar) : Bar(bar) {} void Update() - { + { this->Segments.clear(); - } + } vtkPlotBarSegment* AddSegment( vtkDataArray *xArray, vtkDataArray *yArray, vtkAxis* xAxis, vtkAxis* yAxis, vtkPlotBarSegment *prev = 0) - { + { vtkNew segment; segment->Configure(this->Bar, xArray, yArray, xAxis, yAxis, prev); this->Segments.push_back(segment.GetPointer()); return segment.GetPointer(); - } + } void PaintSegments(vtkContext2D *painter, vtkColorSeries *colorSeries, vtkPen *pen, vtkBrush *brush, float width, float offset, int orientation) - { + { int colorInSeries = 0; bool useColorSeries = this->Segments.size() > 1; for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { if (useColorSeries && colorSeries) - { + { brush->SetColor(colorSeries->GetColorRepeating(colorInSeries++).GetData()); - } - (*it)->Paint(painter, pen, brush, width, offset, orientation); } + (*it)->Paint(painter, pen, brush, width, offset, orientation); } + } vtkIdType GetNearestPoint(const vtkVector2f& point, vtkVector2f* location, float width, float offset, int orientation, vtkIdType* segmentIndex) - { + { vtkIdType segmentIndexCtr = 0; for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { int barIndex = (*it)->GetNearestPoint(point,location,width,offset,orientation); if (barIndex != -1) - { + { if (segmentIndex) - { + { *segmentIndex = segmentIndexCtr; - } - return barIndex; } - ++segmentIndexCtr; + return barIndex; } + ++segmentIndexCtr; + } if (segmentIndex) - { + { *segmentIndex = -1; - } - return -1; } + return -1; + } bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max, float width, float offset, int orientation) { // Selection functionality not supported for stacked plots (yet)... if (this->Segments.size() != 1) - { + { return false; - } + } return this->Segments[0]->SelectPoints(min, max, width, offset, orientation); } @@ -560,10 +560,10 @@ vtkPlotBar::vtkPlotBar() vtkPlotBar::~vtkPlotBar() { if (this->Points) - { + { this->Points->Delete(); this->Points = NULL; - } + } delete this->Private; } @@ -571,35 +571,35 @@ vtkPlotBar::~vtkPlotBar() void vtkPlotBar::Update() { if (!this->Visible) - { + { return; - } + } // First check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } else if(this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || (this->LookupTable && this->LookupTable->GetMTime() > this->BuildTime) || this->MTime > this->BuildTime) - { + { vtkDebugMacro(<< "Updating cached values."); this->UpdateTableCache(table); - } + } else if ((this->XAxis->GetMTime() > this->BuildTime) || (this->YAxis->GetMTime() > this->BuildTime)) - { + { if ((this->LogX != this->XAxis->GetLogScale()) || (this->LogY != this->YAxis->GetLogScale())) - { + { this->LogX = this->XAxis->GetLogScale(); this->LogY = this->YAxis->GetLogScale(); this->UpdateTableCache(table); - } } + } } //----------------------------------------------------------------------------- @@ -609,9 +609,9 @@ bool vtkPlotBar::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotBar."); if (!this->Visible) - { + { return false; - } + } this->Private->PaintSegments(painter,this->ColorSeries, this->Pen,this->Brush, this->Width, this->Offset, this->Orientation); @@ -624,10 +624,10 @@ bool vtkPlotBar::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, int legendIndex) { if (this->ColorSeries) - { + { this->Brush->SetColor( this->ColorSeries->GetColorRepeating(legendIndex).GetData()); - } + } painter->ApplyPen(this->Pen); painter->ApplyBrush(this->Brush); @@ -641,19 +641,19 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled) int seriesLow, seriesHigh, valuesLow, valuesHigh; // Don't re-orient the axes for vertical plots or unscaled bounds: if (this->Orientation == vtkPlotBar::VERTICAL || unscaled) - { + { seriesLow = 0; // Xmin seriesHigh = 1; // Xmax valuesLow = 2; // Ymin valuesHigh = 3; // Ymax - } + } else // HORIZONTAL orientation - { + { seriesLow = 2; // Ymin seriesHigh = 3; // Ymax valuesLow = 0; // Xmin valuesHigh = 1; // Xmax - } + } // Get the x and y arrays (index 0 and 1 respectively) vtkTable *table = this->Data->GetInput(); @@ -661,26 +661,26 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled) 0 : this->Data->GetInputArrayToProcess(0, table); vtkDataArray *y = this->Data->GetInputArrayToProcess(1, table); if (!y) - { + { return; - } + } if (this->UseIndexForXSeries) - { + { bounds[seriesLow] = 0 - (this->Width / 2 ); bounds[seriesHigh] = y->GetNumberOfTuples() + (this->Width/2); - } + } else if (x) - { + { x->GetRange(&bounds[seriesLow]); // We surround our point by Width/2 on either side bounds[seriesLow] -= this->Width / 2.0 + this->Offset; bounds[seriesHigh] += this->Width / 2.0 - this->Offset; - } + } else - { + { return; - } + } y->GetRange(&bounds[valuesLow]); @@ -688,38 +688,38 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled) std::map< int, std::string >::iterator it; for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it ) - { + { y = vtkArrayDownCast(table->GetColumnByName((*it).second.c_str())); y->GetRange(yRange); bounds[valuesHigh] += yRange[1]; - } + } // Bar plots always have one of the value bounds at the origin if (bounds[valuesLow] > 0.0f) - { + { bounds[valuesLow] = 0.0; - } + } else if (bounds[valuesHigh] < 0.0f) - { + { bounds[valuesHigh] = 0.0; - } + } if (unscaled) - { + { vtkAxis* axes[2]; axes[seriesLow / 2] = this->GetXAxis(); axes[valuesLow / 2] = this->GetYAxis(); if (axes[0]->GetLogScaleActive()) - { + { bounds[0] = log10(fabs(bounds[0])); bounds[1] = log10(fabs(bounds[1])); - } + } if (axes[1]->GetLogScaleActive()) - { + { bounds[2] = log10(fabs(bounds[2])); bounds[3] = log10(fabs(bounds[3])); - } } + } vtkDebugMacro(<< "Bounds: " << bounds[0] << "\t" << bounds[1] << "\t" << bounds[2] << "\t" << bounds[3]); } @@ -740,10 +740,10 @@ void vtkPlotBar::GetUnscaledInputBounds(double bounds[4]) void vtkPlotBar::SetOrientation(int orientation) { if (orientation < 0 || orientation > 1) - { + { vtkErrorMacro("Error, invalid orientation value supplied: " << orientation) return; - } + } this->Orientation = orientation; } @@ -795,16 +795,16 @@ vtkStringArray * vtkPlotBar::GetLabels() { // If the label string is empty, return the y column name if (this->Labels) - { + { return this->Labels; - } + } else if (this->AutoLabels) - { + { return this->AutoLabels; - } + } else if (this->Data->GetInput() && this->Data->GetInputArrayToProcess(1, this->Data->GetInput())) - { + { this->AutoLabels = vtkSmartPointer::New(); this->AutoLabels->InsertNextValue(this->Data->GetInputArrayToProcess(1, this->Data->GetInput())->GetName()); @@ -812,24 +812,24 @@ vtkStringArray * vtkPlotBar::GetLabels() std::map< int, std::string >::iterator it; for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it ) - { + { this->AutoLabels->InsertNextValue((*it).second); - } - return this->AutoLabels; } + return this->AutoLabels; + } else - { + { return NULL; - } + } } void vtkPlotBar::SetGroupName(const vtkStdString &name) { if (this->Private->GroupName != name) - { + { this->Private->GroupName = name; this->Modified(); - } + } } vtkStdString vtkPlotBar::GetGroupName() @@ -845,21 +845,21 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table) 0 : this->Data->GetInputArrayToProcess(0, table); vtkDataArray* y = this->Data->GetInputArrayToProcess(1, table); if (!x && !this->UseIndexForXSeries) - { + { vtkErrorMacro(<< "No X column is set (index 0)."); return false; - } + } else if (!y) - { + { vtkErrorMacro(<< "No Y column is set (index 1)."); return false; - } + } else if (!this->UseIndexForXSeries && x->GetNumberOfTuples() != y->GetNumberOfTuples()) - { + { vtkErrorMacro("The x and y columns must have the same number of elements."); return false; - } + } this->Private->Update(); @@ -868,48 +868,48 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table) // Additions for color mapping if (this->ScalarVisibility && !this->ColorArrayName.empty()) - { + { vtkDataArray* c = vtkArrayDownCast(table->GetColumnByName(this->ColorArrayName)); // TODO: Should add support for categorical coloring & try enum lookup if (c) - { + { if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); - } + } this->Colors = this->LookupTable->MapScalars(c, VTK_COLOR_MODE_MAP_SCALARS, -1); prev->Colors = this->Colors; this->Colors->Delete(); - } + } else - { + { this->Colors = NULL; prev->Colors = NULL; - } } + } std::map< int, std::string >::iterator it; for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it ) - { + { y = vtkArrayDownCast(table->GetColumnByName((*it).second.c_str())); prev = this->Private->AddSegment(x,y, this->GetXAxis(), this->GetYAxis(),prev); - } + } this->TooltipDefaultLabelFormat.clear(); // Set the default tooltip according to the segments if (this->Private->Segments.size() > 1) - { + { this->TooltipDefaultLabelFormat = "%s: "; - } + } if (this->IndexedLabels) - { + { this->TooltipDefaultLabelFormat += "%i: "; - } + } this->TooltipDefaultLabelFormat += "%x, %y"; this->BuildTime.Modified(); @@ -927,13 +927,13 @@ void vtkPlotBar::PrintSelf(ostream &os, vtkIndent indent) void vtkPlotBar::SetInputArray(int index, const vtkStdString &name) { if (index == 0 || index == 1) - { + { vtkPlot::SetInputArray(index, name); - } + } else - { + { this->Private->AdditionalSeries[index] = name; - } + } this->AutoLabels = NULL; // No longer valid } @@ -941,9 +941,9 @@ void vtkPlotBar::SetInputArray(int index, const vtkStdString &name) void vtkPlotBar::SetColorSeries(vtkColorSeries *colorSeries) { if (this->ColorSeries == colorSeries) - { + { return; - } + } this->ColorSeries = colorSeries; this->Modified(); } @@ -959,19 +959,19 @@ vtkColorSeries *vtkPlotBar::GetColorSeries() void vtkPlotBar::SetLookupTable(vtkScalarsToColors *lut) { if (this->LookupTable != lut) - { + { this->LookupTable = lut; this->Modified(); - } + } } //----------------------------------------------------------------------------- vtkScalarsToColors *vtkPlotBar::GetLookupTable() { if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); - } + } return this->LookupTable.Get(); } @@ -992,24 +992,24 @@ void vtkPlotBar::CreateDefaultLookupTable() void vtkPlotBar::SelectColorArray(const vtkStdString& arrayName) { if (this->ColorArrayName == arrayName) - { + { return; - } + } vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkWarningMacro(<< "SelectColorArray called with no input table set."); return; - } + } for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i) - { + { if (arrayName == table->GetColumnName(i)) - { + { this->ColorArrayName = arrayName; this->Modified(); return; - } } + } vtkDebugMacro(<< "SelectColorArray called with invalid column name."); this->ColorArrayName = ""; this->Modified(); @@ -1021,30 +1021,30 @@ void vtkPlotBar::SelectColorArray(vtkIdType arrayNum) { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkWarningMacro(<< "SelectColorArray called with no input table set."); return; - } + } vtkDataArray *col = vtkArrayDownCast(table->GetColumn(arrayNum)); // TODO: Should add support for categorical coloring & try enum lookup if (!col) - { + { vtkDebugMacro(<< "SelectColorArray called with invalid column index"); return; - } + } else - { + { const char *arrayName = table->GetColumnName(arrayNum); if (this->ColorArrayName == arrayName || arrayName == 0) - { + { return; - } + } else - { + { this->ColorArrayName = arrayName; this->Modified(); - } } + } } //----------------------------------------------------------------------------- @@ -1057,9 +1057,9 @@ vtkStdString vtkPlotBar::GetColorArrayName() bool vtkPlotBar::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) { if (!this->Selection) - { + { this->Selection = vtkIdTypeArray::New(); - } + } this->Selection->SetNumberOfTuples(0); return this->Private->SelectPoints(min, max, this->Width, this->Offset, @@ -1076,37 +1076,37 @@ vtkStdString vtkPlotBar::GetTooltipLabel(const vtkVector2d &plotPos, vtkStdString tooltipLabel; bool escapeNext = false; for (size_t i = 0; i < baseLabel.length(); ++i) - { + { if (escapeNext) - { + { switch (baseLabel[i]) - { + { case 's': if (segmentIndex >= 0 && this->GetLabels() && segmentIndex < this->GetLabels()->GetNumberOfTuples()) - { + { tooltipLabel += this->GetLabels()->GetValue(segmentIndex); - } + } break; default: // If no match, insert the entire format tag tooltipLabel += "%"; tooltipLabel += baseLabel[i]; break; - } - escapeNext = false; } + escapeNext = false; + } else - { + { if (baseLabel[i] == '%') - { + { escapeNext = true; - } + } else - { + { tooltipLabel += baseLabel[i]; - } } } + } return tooltipLabel; } @@ -1115,10 +1115,10 @@ int vtkPlotBar::GetBarsCount() { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkWarningMacro(<< "GetBarsCount called with no input table set."); return 0; - } + } vtkDataArray* x = this->Data->GetInputArrayToProcess(0, table); return x ? x->GetNumberOfTuples() : 0; } @@ -1130,15 +1130,15 @@ void vtkPlotBar::GetDataBounds(double bounds[2]) // Get the x and y arrays (index 0 and 1 respectively) vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkWarningMacro(<< "GetDataBounds called with no input table set."); bounds[0] = VTK_DOUBLE_MAX; bounds[1] = VTK_DOUBLE_MIN; return; - } + } vtkDataArray* x = this->Data->GetInputArrayToProcess(0, table); if (x) - { + { x->GetRange(bounds); - } + } } diff --git a/Charts/Core/vtkPlotBox.cxx b/Charts/Core/vtkPlotBox.cxx index 2e1ba25c264..4b185de9b39 100644 --- a/Charts/Core/vtkPlotBox.cxx +++ b/Charts/Core/vtkPlotBox.cxx @@ -77,9 +77,9 @@ vtkPlotBox::~vtkPlotBox() delete this->Storage; if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->TitleProperties->Delete(); @@ -89,16 +89,16 @@ vtkPlotBox::~vtkPlotBox() void vtkPlotBox::Update() { if (!this->Visible) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } this->UpdateTableCache(table); } @@ -110,20 +110,20 @@ bool vtkPlotBox::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotBox."); if (!this->Visible) - { + { return false; - } + } if (this->Storage->size() == 0 || this->Storage->at(0).size() < 5) - { + { return false; - } + } vtkChartBox *parent = vtkChartBox::SafeDownCast(this->Parent); int nbCols = static_cast(this->Storage->size()); for (int i = 0; i < nbCols; i++) - { + { vtkStdString colName = parent->GetVisibleColumns()->GetValue(i); int index; this->GetInput()->GetRowData()->GetAbstractArray(colName.c_str(), index); @@ -138,13 +138,13 @@ bool vtkPlotBox::Paint(vtkContext2D *painter) }; if (parent->GetSelectedColumn() == i) - { + { crgba[0] = crgba[0]^255; crgba[1] = crgba[1]^255; crgba[2] = crgba[2]^255; - } - DrawBoxPlot(i, crgba, parent->GetXPosition(i), painter); } + DrawBoxPlot(i, crgba, parent->GetXPosition(i), painter); + } return true; } @@ -155,9 +155,9 @@ void vtkPlotBox::DrawBoxPlot(int i, unsigned char *rgba, double x, { std::vector& colQuartiles = this->Storage->at(i); if (colQuartiles.size() < 5) - { + { return; - } + } painter->ApplyPen(this->Pen); @@ -189,12 +189,12 @@ void vtkPlotBox::DrawBoxPlot(int i, unsigned char *rgba, double x, brush->GetColor(brushColor); // Use a gray pen if the brush is black so the median is always visible if (brushColor[0] == 0 && brushColor[1] == 0 && brushColor[2] == 0) - { + { whitePen->SetWidth(this->Pen->GetWidth()); whitePen->SetColor(128, 128, 128, 128); whitePen->SetOpacity(this->Pen->GetOpacity()); painter->ApplyPen(whitePen.GetPointer()); - } + } painter->DrawLine(xneg, q[2], xpos, q[2]); } @@ -203,9 +203,9 @@ void vtkPlotBox::DrawBoxPlot(int i, unsigned char *rgba, double x, vtkStringArray* vtkPlotBox::GetLabels() { if (this->Labels) - { + { return this->Labels; - } + } return 0; } @@ -213,9 +213,9 @@ vtkStringArray* vtkPlotBox::GetLabels() bool vtkPlotBox::PaintLegend(vtkContext2D* painter, const vtkRectf& rec, int) { if (this->Storage->size() == 0 || this->Storage->at(0).size() < 5) - { + { return false; - } + } vtkChartBox *parent = vtkChartBox::SafeDownCast(this->Parent); @@ -223,14 +223,14 @@ bool vtkPlotBox::PaintLegend(vtkContext2D* painter, const vtkRectf& rec, int) int nbCols = static_cast(this->Storage->size()); for (int i = 0; i < nbCols; i++) - { + { vtkStdString colName = parent->GetVisibleColumns()->GetValue(i); if (this->GetLabels() && this->GetLabels()->GetNumberOfValues() > i) - { + { colName = this->GetLabels()->GetValue(parent->GetColumnId(colName)); - } - painter->DrawString(parent->GetXPosition(i), rec.GetY(), colName); } + painter->DrawString(parent->GetXPosition(i), rec.GetY(), colName); + } return true; } @@ -239,9 +239,9 @@ void vtkPlotBox::SetInputData(vtkTable* table) { if (table == this->Data->GetInput() && (!table || table->GetMTime() < this->BuildTime)) - { + { return; - } + } this->vtkPlot::SetInputData(table); @@ -249,24 +249,24 @@ void vtkPlotBox::SetInputData(vtkTable* table) vtkChartBox *parent = vtkChartBox::SafeDownCast(this->Parent); if (parent && table && updateVisibility) - { + { parent->SetColumnVisibilityAll(false); // By default make the first 10 columns visible in a plot. for (vtkIdType i = 0; i < table->GetNumberOfColumns() && i < 10; ++i) - { + { parent->SetColumnVisibility(table->GetColumnName(i), true); - } } + } else if (parent && updateVisibility) - { + { // No table, therefore no visible columns parent->GetVisibleColumns()->SetNumberOfTuples(0); - } + } // Create a default lookup table is non set yet if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); - } + } } //----------------------------------------------------------------------------- @@ -292,14 +292,14 @@ vtkIdType vtkPlotBox::GetNearestPoint(const vtkVector2f& point, int nbCols = static_cast(this->Storage->size()); for (int i = 0; i < nbCols; i++) - { + { vtkVector2f v; v.SetX(parent->GetXPosition(i)); for (int j = 0; j < 5; j++) - { + { v.SetY((*this->Storage)[i][j]); if (inRange(point, tol, v)) - { + { vtkAxis* axis = parent->GetYAxis(); double min = axis->GetUnscaledMinimum(); double max = axis->GetUnscaledMaximum(); @@ -308,9 +308,9 @@ vtkIdType vtkPlotBox::GetNearestPoint(const vtkVector2f& point, location->SetX(i); location->SetY(y); return static_cast(i); - } } } + } return -1; } @@ -322,9 +322,9 @@ bool vtkPlotBox::UpdateTableCache(vtkTable *table) vtkChartBox *parent = vtkChartBox::SafeDownCast(this->Parent); if (!parent || !table || table->GetNumberOfColumns() == 0) - { + { return false; - } + } vtkStringArray* cols = parent->GetVisibleColumns(); @@ -332,15 +332,15 @@ bool vtkPlotBox::UpdateTableCache(vtkTable *table) vtkIdType rows = table->GetNumberOfRows(); for (vtkIdType i = 0; i < cols->GetNumberOfTuples(); ++i) - { + { std::vector& col = this->Storage->at(i); col.resize(rows); vtkSmartPointer data = vtkArrayDownCast(table->GetColumnByName(cols->GetValue(i))); if (!data) - { + { continue; - } + } vtkAxis* axis = parent->GetYAxis(); // Also need the range from the appropriate axis, to normalize points @@ -349,11 +349,11 @@ bool vtkPlotBox::UpdateTableCache(vtkTable *table) double scale = 1.0f / (max - min); for (vtkIdType j = 0; j < rows; ++j) - { + { col[j] = (data->GetTuple1(j) - min) * scale; - } - std::sort(col.begin(), col.end()); } + std::sort(col.begin(), col.end()); + } this->BuildTime.Modified(); return true; @@ -363,27 +363,27 @@ bool vtkPlotBox::UpdateTableCache(vtkTable *table) void vtkPlotBox::SetLookupTable(vtkScalarsToColors *lut) { if (this->LookupTable != lut) - { + { if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = lut; if (lut) - { + { lut->Register(this); - } - this->Modified(); } + this->Modified(); + } } //----------------------------------------------------------------------------- vtkScalarsToColors *vtkPlotBox::GetLookupTable() { if (this->LookupTable == 0) - { + { this->CreateDefaultLookupTable(); - } + } return this->LookupTable; } @@ -391,17 +391,17 @@ vtkScalarsToColors *vtkPlotBox::GetLookupTable() void vtkPlotBox::SetColumnColor(const vtkStdString& colName, double *rgb) { if (this->LookupTable == 0) - { + { this->CreateDefaultLookupTable(); - } + } int index; this->GetInput()->GetRowData()->GetAbstractArray(colName.c_str(), index); vtkLookupTable* lut = vtkLookupTable::SafeDownCast(this->LookupTable); if (index >= 0 && lut) - { + { lut->SetTableValue(index, rgb[0], rgb[1], rgb[2]); lut->Build(); - } + } } //----------------------------------------------------------------------------- @@ -409,11 +409,11 @@ void vtkPlotBox::CreateDefaultLookupTable() { // There must be an input to create a lookup table if (this->GetInput()) - { + { if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } vtkLookupTable* lut = vtkLookupTable::New(); this->LookupTable = lut; // Consistent Register/UnRegisters. @@ -422,7 +422,7 @@ void vtkPlotBox::CreateDefaultLookupTable() vtkTable *table = this->GetInput(); lut->SetNumberOfColors(table->GetNumberOfColumns()); this->LookupTable->Build(); - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlotFunctionalBag.cxx b/Charts/Core/vtkPlotFunctionalBag.cxx index 5a89d11f1f1..c2bbd185ac4 100644 --- a/Charts/Core/vtkPlotFunctionalBag.cxx +++ b/Charts/Core/vtkPlotFunctionalBag.cxx @@ -47,9 +47,9 @@ vtkPlotFunctionalBag::vtkPlotFunctionalBag() vtkPlotFunctionalBag::~vtkPlotFunctionalBag() { if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } } //----------------------------------------------------------------------------- @@ -69,57 +69,57 @@ bool vtkPlotFunctionalBag::GetVisible() void vtkPlotFunctionalBag::Update() { if (!this->GetVisible()) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } else if(this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || (this->LookupTable && this->LookupTable->GetMTime() > this->BuildTime) || this->MTime > this->BuildTime) - { + { vtkDebugMacro(<< "Updating cached values."); this->UpdateTableCache(table); - } + } else if ((this->XAxis->GetMTime() > this->BuildTime) || (this->YAxis->GetMTime() > this->BuildTime)) - { + { if ((this->LogX != this->XAxis->GetLogScale()) || (this->LogY != this->YAxis->GetLogScale())) - { + { this->UpdateTableCache(table); - } } + } } //----------------------------------------------------------------------------- bool vtkPlotFunctionalBag::UpdateTableCache(vtkTable *table) { if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); this->LookupTable->SetRange(0, table->GetNumberOfColumns()); this->LookupTable->Build(); - } + } this->BagPoints->Reset(); vtkDataArray *array[2] = { 0, 0 }; if (!this->GetDataArrays(table, array)) - { + { this->BuildTime.Modified(); return false; - } + } if (array[1]->GetNumberOfComponents() == 1) - { + { // The input array has one component, manage it as a line this->Line->SetInputData(table, array[0] ? array[0]->GetName() : "", array[1]->GetName()); @@ -128,9 +128,9 @@ bool vtkPlotFunctionalBag::UpdateTableCache(vtkTable *table) this->Line->SetPen(this->Pen); this->Line->SetBrush(this->Brush); this->Line->Update(); - } + } else if (array[1]->GetNumberOfComponents() == 2) - { + { // The input array has 2 components, this must be a bag // with {miny,maxy} tuples vtkDoubleArray* darr = vtkArrayDownCast(array[1]); @@ -140,33 +140,33 @@ bool vtkPlotFunctionalBag::UpdateTableCache(vtkTable *table) bool xAbs = this->XAxis->GetUnscaledMinimum() < 0.; bool yAbs = this->YAxis->GetUnscaledMinimum() < 0.; if (darr) - { + { vtkIdType nbRows = array[1]->GetNumberOfTuples(); this->BagPoints->SetNumberOfPoints(2 * nbRows); for (vtkIdType i = 0; i < nbRows; i++) - { + { double y[2]; darr->GetTuple(i, y); double x = (!this->UseIndexForXSeries && array[0]) ? array[0]->GetVariantValue(i).ToDouble() : static_cast(i); if (this->LogX) - { + { x = xAbs ? log10(fabs(x)) : log10(x); - } + } if (this->LogY) - { + { y[0] = yAbs ? log10(fabs(y[0])) : log10(y[0]); y[1] = yAbs ? log10(fabs(y[1])) : log10(y[1]); - } + } this->BagPoints->SetPoint(2 * i, x, y[0]); this->BagPoints->SetPoint(2 * i + 1, x, y[1]); - } - this->BagPoints->Modified(); } + this->BagPoints->Modified(); } + } this->BuildTime.Modified(); @@ -177,9 +177,9 @@ bool vtkPlotFunctionalBag::UpdateTableCache(vtkTable *table) bool vtkPlotFunctionalBag::GetDataArrays(vtkTable *table, vtkDataArray *array[2]) { if (!table) - { + { return false; - } + } // Get the x and y arrays (index 0 and 1 respectively) array[0] = this->UseIndexForXSeries ? @@ -187,23 +187,23 @@ bool vtkPlotFunctionalBag::GetDataArrays(vtkTable *table, vtkDataArray *array[2] array[1] = this->Data->GetInputArrayToProcess(1, table); if (!array[0] && !this->UseIndexForXSeries) - { + { vtkErrorMacro(<< "No X column is set (index 0)."); return false; - } + } else if (!array[1]) - { + { vtkErrorMacro(<< "No Y column is set (index 1)."); return false; - } + } else if (!this->UseIndexForXSeries && array[0]->GetNumberOfTuples() != array[1]->GetNumberOfTuples()) - { + { vtkErrorMacro("The x and y columns must have the same number of elements. " << array[0]->GetNumberOfTuples() << ", " << array[1]->GetNumberOfTuples()); return false; - } + } return true; } @@ -214,14 +214,14 @@ bool vtkPlotFunctionalBag::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotFunctionalBag."); if (!this->GetVisible()) - { + { return false; - } + } vtkPen* pen = this->GetSelection() ? this->SelectionPen : this->Pen; if (this->IsBag()) - { + { double pwidth = pen->GetWidth(); pen->SetWidth(0.); painter->ApplyPen(pen); @@ -231,12 +231,12 @@ bool vtkPlotFunctionalBag::Paint(vtkContext2D *painter) painter->ApplyBrush(this->Brush); painter->DrawQuadStrip(this->BagPoints.GetPointer()); pen->SetWidth(pwidth); - } + } else - { + { this->Line->SetPen(pen); this->Line->Paint(painter); - } + } return true; } @@ -246,18 +246,18 @@ bool vtkPlotFunctionalBag::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, int index) { if (this->BagPoints->GetNumberOfPoints() > 0) - { + { vtkNew blackPen; blackPen->SetWidth(1.0); blackPen->SetColor(0, 0, 0, 255); painter->ApplyPen(blackPen.GetPointer()); painter->ApplyBrush(this->Brush); painter->DrawRect(rect[0], rect[1], rect[2], rect[3]); - } + } else - { + { this->Line->PaintLegend(painter, rect, index); - } + } return true; } @@ -267,9 +267,9 @@ vtkIdType vtkPlotFunctionalBag::GetNearestPoint(const vtkVector2f& point, vtkVector2f* loc) { if (this->BagPoints->GetNumberOfPoints() == 0) - { + { return this->Line->GetNearestPoint(point, tol, loc); - } + } return -1; } @@ -277,9 +277,9 @@ vtkIdType vtkPlotFunctionalBag::GetNearestPoint(const vtkVector2f& point, bool vtkPlotFunctionalBag::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) { if (!this->IsBag()) - { + { return this->Line->SelectPoints(min, max); - } + } return false; } @@ -287,9 +287,9 @@ bool vtkPlotFunctionalBag::SelectPoints(const vtkVector2f& min, const vtkVector2 bool vtkPlotFunctionalBag::SelectPointsInPolygon(const vtkContextPolygon &polygon) { if (!this->IsBag()) - { + { return this->Line->SelectPointsInPolygon(polygon); - } + } return false; } @@ -297,23 +297,23 @@ bool vtkPlotFunctionalBag::SelectPointsInPolygon(const vtkContextPolygon &polygo void vtkPlotFunctionalBag::GetBounds(double bounds[4]) { if (this->BagPoints->GetNumberOfPoints() > 0) - { + { this->BagPoints->GetBounds(bounds); if (this->LogX) - { + { bounds[0] = log10(bounds[0]); bounds[1] = log10(bounds[1]); } if (this->LogY) - { + { bounds[2] = log10(bounds[2]); bounds[3] = log10(bounds[3]); - } } + } else - { + { this->Line->GetBounds(bounds); - } + } vtkDebugMacro(<< "Bounds: " << bounds[0] << "\t" << bounds[1] << "\t" << bounds[2] << "\t" << bounds[3]); @@ -323,13 +323,13 @@ void vtkPlotFunctionalBag::GetBounds(double bounds[4]) void vtkPlotFunctionalBag::GetUnscaledInputBounds(double bounds[4]) { if (this->BagPoints->GetNumberOfPoints() > 0) - { + { this->BagPoints->GetBounds(bounds); - } + } else - { + { this->Line->GetUnscaledInputBounds(bounds); - } + } vtkDebugMacro(<< "Bounds: " << bounds[0] << "\t" << bounds[1] << "\t" << bounds[2] << "\t" << bounds[3]); @@ -345,27 +345,27 @@ void vtkPlotFunctionalBag::PrintSelf(ostream &os, vtkIndent indent) void vtkPlotFunctionalBag::SetLookupTable(vtkScalarsToColors *lut) { if ( this->LookupTable != lut ) - { + { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = lut; if (lut) - { + { lut->Register(this); - } - this->Modified(); } + this->Modified(); + } } //----------------------------------------------------------------------------- vtkScalarsToColors *vtkPlotFunctionalBag::GetLookupTable() { if ( this->LookupTable == 0 ) - { + { this->CreateDefaultLookupTable(); - } + } return this->LookupTable; } @@ -373,9 +373,9 @@ vtkScalarsToColors *vtkPlotFunctionalBag::GetLookupTable() void vtkPlotFunctionalBag::CreateDefaultLookupTable() { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = vtkLookupTable::New(); // Consistent Register/UnRegisters. this->LookupTable->Register(this); diff --git a/Charts/Core/vtkPlotGrid.cxx b/Charts/Core/vtkPlotGrid.cxx index a63cf25db8e..0acb53177d7 100644 --- a/Charts/Core/vtkPlotGrid.cxx +++ b/Charts/Core/vtkPlotGrid.cxx @@ -48,11 +48,11 @@ vtkPlotGrid::~vtkPlotGrid() bool vtkPlotGrid::Paint(vtkContext2D *painter) { if (!this->XAxis || !this->YAxis) - { + { // Need axes to define where our grid lines should be drawn vtkDebugMacro(<<"No axes set and so grid lines cannot be drawn."); return false; - } + } vtkVector2f x1, x2, y1, y2; this->XAxis->GetPoint1(x1.GetData()); @@ -62,27 +62,27 @@ bool vtkPlotGrid::Paint(vtkContext2D *painter) // in x if (this->XAxis->GetVisible() && this->XAxis->GetGridVisible()) - { + { vtkFloatArray *xLines = this->XAxis->GetTickScenePositions(); painter->ApplyPen(this->XAxis->GetGridPen()); float *xPositions = xLines->GetPointer(0); for (int i = 0; i < xLines->GetNumberOfTuples(); ++i) - { + { painter->DrawLine(xPositions[i], y1.GetY(), xPositions[i], y2.GetY()); - } } + } // in y if (this->YAxis->GetVisible() && this->YAxis->GetGridVisible()) - { + { vtkFloatArray *yLines = this->YAxis->GetTickScenePositions(); painter->ApplyPen(this->YAxis->GetGridPen()); float *yPositions = yLines->GetPointer(0); for (int i = 0; i < yLines->GetNumberOfTuples(); ++i) - { + { painter->DrawLine(x1.GetX(), yPositions[i], x2.GetX(), yPositions[i]); - } } + } return true; } diff --git a/Charts/Core/vtkPlotHistogram2D.cxx b/Charts/Core/vtkPlotHistogram2D.cxx index 6ff2d3fc8f0..dad29bad32d 100644 --- a/Charts/Core/vtkPlotHistogram2D.cxx +++ b/Charts/Core/vtkPlotHistogram2D.cxx @@ -48,16 +48,16 @@ void vtkPlotHistogram2D::Update() bool vtkPlotHistogram2D::Paint(vtkContext2D *painter) { if (this->Output) - { + { if (this->Input) - { + { double bounds[4]; this->GetBounds(bounds); this->Position = vtkRectf(bounds[0], bounds[2], bounds[1] - bounds[0], bounds[3] - bounds[2]); - } - painter->DrawImage(this->Position, this->Output); } + painter->DrawImage(this->Position, this->Output); + } return true; } @@ -90,7 +90,7 @@ vtkScalarsToColors * vtkPlotHistogram2D::GetTransferFunction() void vtkPlotHistogram2D::GetBounds(double bounds[4]) { if (this->Input) - { + { int *extent = this->Input->GetExtent(); bounds[0] = this->Input->GetOrigin()[0]; bounds[1] = bounds[0] + @@ -99,11 +99,11 @@ void vtkPlotHistogram2D::GetBounds(double bounds[4]) bounds[2] = this->Input->GetOrigin()[1]; bounds[3] = bounds[2] + (extent[3] - extent[2] + 1) * this->Input->GetSpacing()[1]; - } + } else - { + { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; - } + } } //----------------------------------------------------------------------------- @@ -133,9 +133,9 @@ vtkIdType vtkPlotHistogram2D::GetNearestPoint(const vtkVector2f& point, point.GetX() > bounds[1]+spacing[0] || point.GetY() < bounds[2] || point.GetY() > bounds[3]+spacing[1]) - { + { return -1; - } + } // Can't use vtkImageData::FindPoint() / GetPoint(), as ImageData points are // rendered as the bottom left corner of a histogram cell, not the center @@ -171,11 +171,11 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2d &plotPos, // Parse TooltipLabelFormat and build tooltipLabel bool escapeNext = false; for (size_t i = 0; i < format.length(); ++i) - { + { if (escapeNext) - { + { switch (format[i]) - { + { case 'x': tooltipLabel += this->GetNumber(plotPos.GetX(), this->XAxis); break; @@ -186,45 +186,45 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2d &plotPos, if (this->XAxis->GetTickLabels() && pointX >= 0 && pointX < this->XAxis->GetTickLabels()->GetNumberOfTuples()) - { + { tooltipLabel += this->XAxis->GetTickLabels()->GetValue(pointX); - } + } break; case 'j': if (this->YAxis->GetTickLabels() && pointY >= 0 && pointY < this->YAxis->GetTickLabels()->GetNumberOfTuples()) - { + { tooltipLabel += this->YAxis->GetTickLabels()->GetValue(pointY); - } + } break; case 'v': if (pointX >= 0 && pointX < width && pointY >= 0 && pointY < height) - { + { tooltipLabel += this->GetNumber(this->Input->GetScalarComponentAsDouble( pointX, pointY, 0, 0), NULL); - } + } break; default: // If no match, insert the entire format tag tooltipLabel += "%"; tooltipLabel += format[i]; break; - } - escapeNext = false; } + escapeNext = false; + } else - { + { if (format[i] == '%') - { + { escapeNext = true; - } + } else - { + { tooltipLabel += format[i]; - } } } + } return tooltipLabel; } @@ -232,13 +232,13 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2d &plotPos, void vtkPlotHistogram2D::GenerateHistogram() { if (!this->Input) - { + { return; - } + } if (!this->Output) - { + { this->Output = vtkSmartPointer::New(); - } + } this->Output->SetExtent(this->Input->GetExtent()); this->Output->AllocateScalars(VTK_UNSIGNED_CHAR, 4); @@ -248,10 +248,10 @@ void vtkPlotHistogram2D::GenerateHistogram() reinterpret_cast(this->Output->GetScalarPointer(0,0,0)); if (this->TransferFunction) - { + { this->TransferFunction->MapScalarsThroughTable2(input, output, VTK_DOUBLE, dimension, 1, 4); - } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlotLine.cxx b/Charts/Core/vtkPlotLine.cxx index 2ad93566bfd..5ed0c47fdb5 100644 --- a/Charts/Core/vtkPlotLine.cxx +++ b/Charts/Core/vtkPlotLine.cxx @@ -45,101 +45,101 @@ bool vtkPlotLine::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotLine."); if (!this->Visible || !this->Points) - { + { return false; - } + } // Draw the line between the points painter->ApplyPen(this->Pen); if (this->BadPoints && this->BadPoints->GetNumberOfTuples() > 0) - { + { // draw lines skipping bad points float *points = static_cast(this->Points->GetVoidPointer(0)); const int pointSize = 2; vtkIdType lastGood = 0; for (vtkIdType i = 0; i < this->BadPoints->GetNumberOfTuples(); i++) - { + { vtkIdType id = this->BadPoints->GetValue(i); // render from last good point to one before this bad point if (id - lastGood > 2) - { + { int start = lastGood + 1; int numberOfPoints = id - start; if (!this->PolyLine) - { + { // Start at the next point if the last bad point was the first point // of a line segment. if (start % 2 == 0) - { + { ++start; --numberOfPoints; - } + } // Stops at the previous point if the next bad point is the second point // of a line segment. if (numberOfPoints % 2 == 1) - { + { --numberOfPoints; - } } + } if (this->PolyLine) - { + { painter->DrawPoly(points + pointSize * start, numberOfPoints); - } + } else if (start < this->Points->GetNumberOfPoints() && numberOfPoints > 0) - { + { painter->DrawLines(points + pointSize * start, numberOfPoints); - } } + } lastGood = id; - } + } // render any trailing good points if (this->Points->GetNumberOfPoints() - lastGood > 2) - { + { int start = lastGood + 1; int numberOfPoints = this->Points->GetNumberOfPoints() - start; if (!this->PolyLine) - { + { // Start at the next point if the last bad point was the first point // of a line segment. if (start % 2 == 0) - { + { ++start; --numberOfPoints; - } + } // Stops at the previous point if the next bad point is the second point // of a line segment. if (numberOfPoints % 2 == 1) - { + { --numberOfPoints; - } } + } if (this->PolyLine) - { + { painter->DrawPoly(points + pointSize * start, numberOfPoints); - } + } else if (start < this->Points->GetNumberOfPoints() && numberOfPoints > 0) - { + { painter->DrawLines(points + pointSize * start, numberOfPoints); - } } } + } else - { + { // draw lines between all points if (this->PolyLine) - { + { painter->DrawPoly(this->Points); - } + } else - { + { painter->DrawLines(this->Points); - } } + } return this->vtkPlotPoints::Paint(painter); } diff --git a/Charts/Core/vtkPlotLine3D.cxx b/Charts/Core/vtkPlotLine3D.cxx index 39f19fee6cc..25c21feb0f9 100644 --- a/Charts/Core/vtkPlotLine3D.cxx +++ b/Charts/Core/vtkPlotLine3D.cxx @@ -41,16 +41,16 @@ bool vtkPlotLine3D::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotLine3D."); if (!this->Visible || this->Points.size() == 0) - { + { return false; - } + } // Get the 3D context. vtkContext3D *context = painter->GetContext3D(); if(context == NULL) - { + { return false; - } + } // Draw the line between the points context->ApplyPen(this->Pen); diff --git a/Charts/Core/vtkPlotParallelCoordinates.cxx b/Charts/Core/vtkPlotParallelCoordinates.cxx index 0abf2046f1c..3b6e9bd5171 100644 --- a/Charts/Core/vtkPlotParallelCoordinates.cxx +++ b/Charts/Core/vtkPlotParallelCoordinates.cxx @@ -76,29 +76,29 @@ vtkPlotParallelCoordinates::~vtkPlotParallelCoordinates() { delete this->Storage; if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } if ( this->Colors != 0 ) - { + { this->Colors->UnRegister(this); - } + } } //----------------------------------------------------------------------------- void vtkPlotParallelCoordinates::Update() { if (!this->Visible) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } this->UpdateTableCache(table); } @@ -110,16 +110,16 @@ bool vtkPlotParallelCoordinates::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotParallelCoordinates."); if (!this->Visible) - { + { return false; - } + } painter->ApplyPen(this->Pen); if (this->Storage->size() == 0) - { + { return false; - } + } size_t cols = this->Storage->size(); size_t rows = this->Storage->at(0).size(); @@ -130,69 +130,69 @@ bool vtkPlotParallelCoordinates::Paint(vtkContext2D *painter) vtkChartParallelCoordinates::SafeDownCast(this->Parent); for (size_t i = 0; i < cols; ++i) - { + { this->Storage->AxisPos[i] = parent->GetAxis(int(i)) ? parent->GetAxis(int(i))->GetPoint1()[0] : 0; - } + } vtkIdType selection = 0; vtkIdType id = 0; vtkIdType selectionSize = 0; if (this->Selection) - { + { selectionSize = this->Selection->GetNumberOfTuples(); if (selectionSize) - { + { this->Selection->GetTypedTuple(selection, &id); - } } + } // Draw all of the lines painter->ApplyPen(this->Pen); int ncComps(0); if (this->ScalarVisibility && this->Colors) - { + { ncComps = static_cast(this->Colors->GetNumberOfComponents()); - } + } if (this->ScalarVisibility && this->Colors && ncComps == 4) - { + { for (size_t i = 0, nc = 0; i < rows; ++i, nc += ncComps) - { + { for (size_t j = 0; j < cols; ++j) - { + { line[j].Set(this->Storage->AxisPos[j], (*this->Storage)[j][i]); - } + } painter->GetPen()->SetColor(this->Colors->GetPointer(nc)); painter->DrawPoly(line[0].GetData(), static_cast(cols)); - } } + } else - { + { for (size_t i = 0; i < rows; ++i) - { + { for (size_t j = 0; j < cols; ++j) - { + { line[j].Set(this->Storage->AxisPos[j], (*this->Storage)[j][i]); - } - painter->DrawPoly(line[0].GetData(), static_cast(cols)); } + painter->DrawPoly(line[0].GetData(), static_cast(cols)); } + } // Now draw the selected lines if (this->Selection) - { + { painter->GetPen()->SetColor(255, 0, 0, 100); for (vtkIdType i = 0; i < this->Selection->GetNumberOfTuples(); ++i) - { + { for (size_t j = 0; j < cols; ++j) - { + { this->Selection->GetTypedTuple(i, &id); line[j].Set(this->Storage->AxisPos[j], (*this->Storage)[j][id]); - } - painter->DrawPoly(line[0].GetData(), static_cast(cols)); } + painter->DrawPoly(line[0].GetData(), static_cast(cols)); } + } delete[] line; @@ -220,43 +220,43 @@ bool vtkPlotParallelCoordinates::SetSelectionRange(int axis, float low, float high) { if (!this->Selection) - { + { this->Storage->SelectionInitialized = false; this->Selection = vtkIdTypeArray::New(); - } + } if (this->Storage->SelectionInitialized) - { + { // Further refine the selection that has already been made vtkIdTypeArray *array = vtkIdTypeArray::New(); std::vector& col = this->Storage->at(axis); for (vtkIdType i = 0; i < this->Selection->GetNumberOfTuples(); ++i) - { + { vtkIdType id = 0; this->Selection->GetTypedTuple(i, &id); if (col[id] >= low && col[id] <= high) - { + { // Remove this point - no longer selected array->InsertNextValue(id); - } } + } this->Selection->DeepCopy(array); array->Delete(); - } + } else - { + { // First run - ensure the selection list is empty and build it up std::vector& col = this->Storage->at(axis); for (size_t i = 0; i < col.size(); ++i) - { + { if (col[i] >= low && col[i] <= high) - { + { // Remove this point - no longer selected this->Selection->InsertNextValue(i); - } } - this->Storage->SelectionInitialized = true; } + this->Storage->SelectionInitialized = true; + } return true; } @@ -265,9 +265,9 @@ bool vtkPlotParallelCoordinates::ResetSelectionRange() { this->Storage->SelectionInitialized = false; if (this->Selection) - { + { this->Selection->SetNumberOfTuples(0); - } + } return true; } @@ -276,9 +276,9 @@ void vtkPlotParallelCoordinates::SetInputData(vtkTable* table) { if (table == this->Data->GetInput() && (!table || table->GetMTime() < this->BuildTime)) - { + { return; - } + } bool updateVisibility = table != this->Data->GetInput(); this->vtkPlot::SetInputData(table); @@ -286,19 +286,19 @@ void vtkPlotParallelCoordinates::SetInputData(vtkTable* table) vtkChartParallelCoordinates::SafeDownCast(this->Parent); if (parent && table && updateVisibility) - { + { parent->SetColumnVisibilityAll(false); // By default make the first 10 columns visible in a plot. for (vtkIdType i = 0; i < table->GetNumberOfColumns() && i < 10; ++i) - { + { parent->SetColumnVisibility(table->GetColumnName(i), true); - } } + } else if (parent && updateVisibility) - { + { // No table, therefore no visible columns parent->GetVisibleColumns()->SetNumberOfTuples(0); - } + } } //----------------------------------------------------------------------------- @@ -308,9 +308,9 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table) vtkChartParallelCoordinates *parent = vtkChartParallelCoordinates::SafeDownCast(this->Parent); if (!parent || !table || table->GetNumberOfColumns() == 0) - { + { return false; - } + } vtkStringArray* cols = parent->GetVisibleColumns(); @@ -319,16 +319,16 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table) vtkIdType rows = table->GetNumberOfRows(); for (vtkIdType i = 0; i < cols->GetNumberOfTuples(); ++i) - { + { std::vector& col = this->Storage->at(i); vtkAxis* axis = parent->GetAxis(i); col.resize(rows); vtkSmartPointer data = vtkArrayDownCast(table->GetColumnByName(cols->GetValue(i))); if (!data) - { + { if (table->GetColumnByName(cols->GetValue(i))->IsA("vtkStringArray")) - { + { // We have a different kind of column - attempt to make it into an enum vtkStringToCategory* stoc = vtkStringToCategory::New(); stoc->SetInputData(table); @@ -340,39 +340,39 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table) vtkTable* table2 = vtkTable::SafeDownCast(stoc->GetOutput()); vtkTable* stringTable = vtkTable::SafeDownCast(stoc->GetOutput(1)); if (table2) - { + { data = vtkArrayDownCast(table2->GetColumnByName("enumPC")); - } + } if (stringTable && stringTable->GetColumnByName("Strings")) - { + { vtkStringArray* strings = vtkArrayDownCast(stringTable->GetColumnByName("Strings")); vtkSmartPointer arr = vtkSmartPointer::New(); for (vtkIdType j = 0; j < strings->GetNumberOfTuples(); ++j) - { + { arr->InsertNextValue(j); - } + } // Now we need to set the range on the string axis axis->SetCustomTickPositions(arr, strings); if (strings->GetNumberOfTuples() > 1) - { + { axis->SetUnscaledRange(0.0, strings->GetNumberOfTuples()-1); - } + } else - { + { axis->SetUnscaledRange(-0.1, 0.1); - } - axis->Update(); } - stoc->Delete(); + axis->Update(); } + stoc->Delete(); + } // If we still don't have a valid data array then skip this column. if (!data) - { + { continue; - } } + } // Also need the range from the appropriate axis, to normalize points double min = axis->GetUnscaledMinimum(); @@ -380,34 +380,34 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table) double scale = 1.0f / (max - min); for (vtkIdType j = 0; j < rows; ++j) - { + { col[j] = (data->GetTuple1(j) - min) * scale; - } } + } // Additions for color mapping if (this->ScalarVisibility && !this->ColorArrayName.empty()) - { + { vtkDataArray* c = vtkArrayDownCast(table->GetColumnByName(this->ColorArrayName)); // TODO: Should add support for categorical coloring & try enum lookup if (c) - { + { if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); - } + } this->Colors = this->LookupTable->MapScalars(c, VTK_COLOR_MODE_MAP_SCALARS, -1); // Consistent register and unregisters this->Colors->Register(this); this->Colors->Delete(); - } + } else - { + { this->Colors->UnRegister(this); this->Colors = 0; - } } + } this->BuildTime.Modified(); return true; @@ -417,27 +417,27 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table) void vtkPlotParallelCoordinates::SetLookupTable(vtkScalarsToColors *lut) { if ( this->LookupTable != lut ) - { + { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = lut; if (lut) - { + { lut->Register(this); - } - this->Modified(); } + this->Modified(); + } } //----------------------------------------------------------------------------- vtkScalarsToColors *vtkPlotParallelCoordinates::GetLookupTable() { if ( this->LookupTable == 0 ) - { + { this->CreateDefaultLookupTable(); - } + } return this->LookupTable; } @@ -445,9 +445,9 @@ vtkScalarsToColors *vtkPlotParallelCoordinates::GetLookupTable() void vtkPlotParallelCoordinates::CreateDefaultLookupTable() { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = vtkLookupTable::New(); // Consistent Register/UnRegisters. this->LookupTable->Register(this); @@ -459,23 +459,23 @@ void vtkPlotParallelCoordinates::SelectColorArray(const vtkStdString &arrayName) { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "SelectColorArray called with no input table set."); return; - } + } if (this->ColorArrayName == arrayName) - { + { return; - } + } for (vtkIdType c = 0; c < table->GetNumberOfColumns(); ++c) - { + { if (table->GetColumnName(c) == arrayName) - { + { this->ColorArrayName = arrayName; this->Modified(); return; - } } + } vtkDebugMacro(<< "SelectColorArray called with invalid column name."); this->ColorArrayName = ""; this->Modified(); @@ -493,29 +493,29 @@ void vtkPlotParallelCoordinates::SelectColorArray(vtkIdType arrayNum) { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "SelectColorArray called with no input table set."); return; - } + } vtkDataArray *col = vtkArrayDownCast(table->GetColumn(arrayNum)); // TODO: Should add support for categorical coloring & try enum lookup if (!col) - { + { vtkDebugMacro(<< "SelectColorArray called with invalid column index"); return; - } + } else - { + { if (this->ColorArrayName == table->GetColumnName(arrayNum)) - { + { return; - } + } else - { + { this->ColorArrayName = table->GetColumnName(arrayNum); this->Modified(); - } } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlotPie.cxx b/Charts/Core/vtkPlotPie.cxx index cfe238b19f1..446b66e91a0 100644 --- a/Charts/Core/vtkPlotPie.cxx +++ b/Charts/Core/vtkPlotPie.cxx @@ -36,9 +36,9 @@ A SumData(A *a, int n) { A sum = 0; for (int i = 0; i < n; ++i) - { + { sum += a[i]; - } + } return sum; } @@ -52,11 +52,11 @@ void CopyToPoints(vtkPoints2D *points, A *a, int n) float startAngle = 0.0; for (int i = 0; i < n; ++i) - { + { data[2*i] = startAngle; data[2*i+1] = startAngle + ((static_cast(a[i]) / sum) * 360.0); startAngle = data[2*i+1]; - } + } } } @@ -64,11 +64,11 @@ class vtkPlotPiePrivate { public: vtkPlotPiePrivate() - { + { this->CenterX = 0; this->CenterY = 0; this->Radius = 0; - } + } float CenterX; float CenterY; @@ -93,10 +93,10 @@ vtkPlotPie::~vtkPlotPie() { delete this->Private; if (this->Points) - { + { this->Points->Delete(); this->Points = 0; - } + } this->Private = 0; } @@ -104,29 +104,29 @@ vtkPlotPie::~vtkPlotPie() bool vtkPlotPie::Paint(vtkContext2D *painter) { if (!this->Visible) - { + { return false; - } + } // First check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Paint event called with no input table set."); return false; - } + } else if(this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || this->MTime > this->BuildTime) - { + { vtkDebugMacro(<< "Paint event called with outdated table cache. Updating."); this->UpdateTableCache(table); - } + } float* data = static_cast(this->Points->GetVoidPointer(0)); for (int i = 0; i < this->Points->GetNumberOfPoints(); ++i) - { + { painter->GetBrush() ->SetColor(this->ColorSeries->GetColorRepeating(i).GetData()); @@ -135,7 +135,7 @@ bool vtkPlotPie::Paint(vtkContext2D *painter) 0.0, 0.0, data[2*i], data[2*i+1] ); - } + } this->PaintChildren(painter); return true; @@ -162,7 +162,7 @@ void vtkPlotPie::SetDimensions(int arg1, int arg2, int arg3, int arg4) { if (arg1 != this->Dimensions[0] || arg2 != this->Dimensions[1] || arg3 != this->Dimensions[2] || arg4 != this->Dimensions[3]) - { + { this->Dimensions[0] = arg1; this->Dimensions[1] = arg2; this->Dimensions[2] = arg3; @@ -173,7 +173,7 @@ void vtkPlotPie::SetDimensions(int arg1, int arg2, int arg3, int arg4) this->Private->Radius = this->Dimensions[2] < this->Dimensions[3] ? 0.5 * this->Dimensions[2] : 0.5 * this->Dimensions[3]; this->Modified(); - } + } } void vtkPlotPie::SetDimensions(int arg[4]) @@ -186,9 +186,9 @@ void vtkPlotPie::SetDimensions(int arg[4]) void vtkPlotPie::SetColorSeries(vtkColorSeries *colorSeries) { if (this->ColorSeries == colorSeries) - { + { return; - } + } this->ColorSeries = colorSeries; this->Modified(); } @@ -208,13 +208,13 @@ vtkIdType vtkPlotPie::GetNearestPoint(const vtkVector2f& point, float y = point.GetY() - this->Private->CenterY; if (sqrt((x*x) + (y*y)) <= this->Private->Radius) - { + { float *angles = static_cast(this->Points->GetVoidPointer(0)); float pointAngle = vtkMath::DegreesFromRadians(atan2(y,x)); if (pointAngle < 0) - { + { pointAngle = 180.0 + (180.0 + pointAngle); - } + } float *lbound = std::lower_bound(angles, angles + (this->Points->GetNumberOfPoints() * 2), pointAngle); @@ -228,7 +228,7 @@ vtkIdType vtkPlotPie::GetNearestPoint(const vtkVector2f& point, value->SetX(ret); value->SetY(data->GetTuple1(ret)); return ret; - } + } return -1; } @@ -246,24 +246,24 @@ bool vtkPlotPie::UpdateTableCache(vtkTable *table) vtkDataArray* data = this->Data->GetInputArrayToProcess(0, table); if (!data) - { + { vtkErrorMacro(<< "No data set (index 0)."); return false; - } + } if (!this->Points) - { + { this->Points = vtkPoints2D::New(); - } + } switch (data->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints(this->Points, static_cast(data->GetVoidPointer(0)), data->GetNumberOfTuples())); - } + } this->BuildTime.Modified(); return true; diff --git a/Charts/Core/vtkPlotPoints.cxx b/Charts/Core/vtkPlotPoints.cxx index b22143569a4..0d6e316ab72 100644 --- a/Charts/Core/vtkPlotPoints.cxx +++ b/Charts/Core/vtkPlotPoints.cxx @@ -52,12 +52,12 @@ class vtkPlotPoints::VectorPIMPL : public std::vector { this->reserve(n); for (size_t i = 0; i < n; ++i) - { + { vtkIndexedVector2f tmp; tmp.index = i; tmp.pos = array[i]; this->push_back(tmp); - } + } } }; @@ -88,70 +88,70 @@ vtkPlotPoints::vtkPlotPoints() vtkPlotPoints::~vtkPlotPoints() { if (this->Points) - { + { this->Points->Delete(); this->Points = NULL; - } + } delete this->Sorted; if (this->BadPoints) - { + { this->BadPoints->Delete(); this->BadPoints = NULL; - } + } if (this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } if ( this->Colors != 0 ) - { + { this->Colors->UnRegister(this); - } + } } //----------------------------------------------------------------------------- void vtkPlotPoints::Update() { if (!this->Visible) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); if (table && !this->ValidPointMaskName.empty() && table->GetColumnByName(this->ValidPointMaskName)) - { + { this->ValidPointMask = vtkArrayDownCast( table->GetColumnByName(this->ValidPointMaskName)); - } + } else - { + { this->ValidPointMask = 0; - } + } if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } else if(this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || (this->LookupTable && this->LookupTable->GetMTime() > this->BuildTime) || this->MTime > this->BuildTime) - { + { vtkDebugMacro(<< "Updating cached values."); this->UpdateTableCache(table); - } + } else if (this->XAxis && this->YAxis && ((this->XAxis->GetMTime() > this->BuildTime) || (this->YAxis->GetMTime() > this->BuildTime))) - { + { if ((this->LogX != this->XAxis->GetLogScale()) || (this->LogY != this->YAxis->GetLogScale())) - { + { this->UpdateTableCache(table); - } } + } } //----------------------------------------------------------------------------- @@ -161,24 +161,24 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotPoints."); if (!this->Visible || !this->Points || this->Points->GetNumberOfPoints() == 0) - { + { return false; - } + } // Maintain legacy behavior (using pen width) if MarkerSize was not set float width = this->MarkerSize; if (width < 0.0f) - { + { width = this->Pen->GetWidth() * 2.3; if (width < 8.0) - { + { width = 8.0; - } } + } // If there is a marker style, then draw the marker for each point too if (this->MarkerStyle != VTK_MARKER_NONE) - { + { painter->ApplyPen(this->Pen); painter->ApplyBrush(this->Brush); painter->GetPen()->SetWidth(width); @@ -187,57 +187,57 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter) unsigned char *colors = 0; int nColorComponents = 0; if (this->ScalarVisibility && this->Colors) - { + { colors = this->Colors->GetPointer(0); nColorComponents = static_cast(this->Colors->GetNumberOfComponents()); - } + } if (this->BadPoints && this->BadPoints->GetNumberOfTuples() > 0) - { + { vtkIdType lastGood = 0; for (vtkIdType i = 0; i < this->BadPoints->GetNumberOfTuples(); i++) - { + { vtkIdType id = this->BadPoints->GetValue(i); // render from last good point to one before this bad point if (id - lastGood > 2) - { + { painter->DrawMarkers(this->MarkerStyle, false, points + 2 * (lastGood + 1), id - lastGood - 1, colors ? colors + 4 * (lastGood + 1) : 0, nColorComponents); - } + } lastGood = id; - } + } // render any trailing good points if (this->Points->GetNumberOfPoints() - lastGood > 2) - { + { painter->DrawMarkers(this->MarkerStyle, false, points + 2 * (lastGood + 1), this->Points->GetNumberOfPoints() - lastGood - 1, colors ? colors + 4 * (lastGood + 1) : 0, nColorComponents); - } - } + } + } else - { + { // draw all of the points painter->DrawMarkers(this->MarkerStyle, false, points, this->Points->GetNumberOfPoints(), colors, nColorComponents); - } } + } // Now add some decorations for our selected points... if (this->Selection && this->Selection->GetNumberOfTuples()) - { + { if (this->Selection->GetMTime() > this->SelectedPoints->GetMTime() || this->GetMTime() > this->SelectedPoints->GetMTime()) - { + { float *f = vtkArrayDownCast( this->Points->GetData())->GetPointer(0); int nSelected(static_cast(this->Selection->GetNumberOfTuples())); @@ -245,31 +245,31 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter) this->SelectedPoints->SetNumberOfTuples(nSelected); float *selectedPtr = static_cast(this->SelectedPoints->GetVoidPointer(0)); for (int i = 0; i < nSelected; ++i) - { + { *(selectedPtr++) = f[2 * this->Selection->GetValue(i)]; *(selectedPtr++) = f[2 * this->Selection->GetValue(i) + 1]; - } } + } vtkDebugMacro(<<"Selection set " << this->Selection->GetNumberOfTuples()); painter->GetPen()->SetColor(this->SelectionPen->GetColor()); painter->GetPen()->SetOpacity(this->SelectionPen->GetOpacity()); painter->GetPen()->SetWidth(width + 2.7); if (this->MarkerStyle == VTK_MARKER_NONE) - { + { painter->DrawMarkers(VTK_MARKER_PLUS, false, static_cast( this->SelectedPoints->GetVoidPointer(0)), this->SelectedPoints->GetNumberOfTuples()); - } + } else - { + { painter->DrawMarkers(this->MarkerStyle, true, static_cast( this->SelectedPoints->GetVoidPointer(0)), this->SelectedPoints->GetNumberOfTuples()); - } } + } return true; } @@ -279,19 +279,19 @@ bool vtkPlotPoints::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, int) { if (this->MarkerStyle) - { + { float width = this->Pen->GetWidth() * 2.3; if (width < 8.0) - { + { width = 8.0; - } + } painter->ApplyPen(this->Pen); painter->ApplyBrush(this->Brush); painter->GetPen()->SetWidth(width); float point[] = { rect[0]+ 0.5f * rect[2], rect[1] + 0.5f * rect[3] }; painter->DrawMarkers(this->MarkerStyle, false, point, 1); - } + } return true; } @@ -299,10 +299,10 @@ bool vtkPlotPoints::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, void vtkPlotPoints::GetBounds(double bounds[4]) { if (this->Points) - { + { // There are bad points in the series - need to do this ourselves. this->CalculateBounds(bounds); - } + } vtkDebugMacro(<< "Bounds: " << bounds[0] << "\t" << bounds[1] << "\t" << bounds[2] << "\t" << bounds[3]); } @@ -312,9 +312,9 @@ void vtkPlotPoints::GetUnscaledInputBounds(double bounds[4]) { this->CalculateUnscaledInputBounds(); for (int i = 0; i < 4; ++i) - { + { bounds[i] = this->UnscaledInputBounds[i]; - } + } vtkDebugMacro( << "Bounds: " << bounds[0] << "\t" << bounds[1] << "\t" << bounds[2] << "\t" << bounds[3]); @@ -327,13 +327,13 @@ bool compVector3fX(const vtkIndexedVector2f& v1, const vtkIndexedVector2f& v2) { if (v1.pos.GetX() < v2.pos.GetX()) - { + { return true; - } + } else - { + { return false; - } + } } // See if the point is within tolerance. @@ -342,13 +342,13 @@ bool inRange(const vtkVector2f& point, const vtkVector2f& tol, { if (current.GetX() > point.GetX() - tol.GetX() && current.GetX() < point.GetX() + tol.GetX() && current.GetY() > point.GetY() - tol.GetY() && current.GetY() < point.GetY() + tol.GetY()) - { + { return true; - } + } else - { + { return false; - } + } } } @@ -358,13 +358,13 @@ void vtkPlotPoints::CreateSortedPoints() { // Sort the data if it has not been done already... if (!this->Sorted) - { + { vtkIdType n = this->Points->GetNumberOfPoints(); vtkVector2f* data = static_cast(this->Points->GetVoidPointer(0)); this->Sorted = new VectorPIMPL(data, n); std::sort(this->Sorted->begin(), this->Sorted->end(), compVector3fX); - } + } } //----------------------------------------------------------------------------- @@ -374,9 +374,9 @@ vtkIdType vtkPlotPoints::GetNearestPoint(const vtkVector2f& point, { // Right now doing a simple bisector search of the array. if (!this->Points) - { + { return -1; - } + } this->CreateSortedPoints(); // Set up our search array, use the STL lower_bound algorithm @@ -392,18 +392,18 @@ vtkIdType vtkPlotPoints::GetNearestPoint(const vtkVector2f& point, // Now consider the y axis float highX = point.GetX() + tol.GetX(); while (low != v.end()) - { + { if (inRange(point, tol, (*low).pos)) - { + { *location = (*low).pos; return static_cast((*low).index); - } + } else if (low->pos.GetX() > highX) - { + { break; - } - ++low; } + ++low; + } return -1; } @@ -411,15 +411,15 @@ vtkIdType vtkPlotPoints::GetNearestPoint(const vtkVector2f& point, bool vtkPlotPoints::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) { if (!this->Points) - { + { return false; - } + } this->CreateSortedPoints(); if (!this->Selection) - { + { this->Selection = vtkIdTypeArray::New(); - } + } this->Selection->SetNumberOfTuples(0); // Set up our search array, use the STL lower_bound algorithm @@ -436,24 +436,24 @@ bool vtkPlotPoints::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) std::vector selected; // Iterate until we are out of range in X while (low != v.end()) - { + { if (low->pos.GetX() >= min.GetX() && low->pos.GetX() <= max.GetX() && low->pos.GetY() >= min.GetY() && low->pos.GetY() <= max.GetY()) - { + { selected.push_back(low->index); - } + } else if (low->pos.GetX() > max.GetX()) - { + { break; - } + } ++low; - } + } this->Selection->SetNumberOfTuples(selected.size()); vtkIdType *ptr = static_cast(this->Selection->GetVoidPointer(0)); for (size_t i = 0; i < selected.size(); ++i) - { + { ptr[i] = selected[i]; - } + } std::sort(ptr, ptr + selected.size()); this->Selection->Modified(); return this->Selection->GetNumberOfTuples() > 0; @@ -463,35 +463,35 @@ bool vtkPlotPoints::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) bool vtkPlotPoints::SelectPointsInPolygon(const vtkContextPolygon &polygon) { if (!this->Points) - { + { // nothing to select return false; - } + } if (!this->Selection) - { + { // create selection object this->Selection = vtkIdTypeArray::New(); - } + } else - { + { // clear previous selection this->Selection->SetNumberOfValues(0); - } + } for(vtkIdType pointId = 0; pointId < this->Points->GetNumberOfPoints(); pointId++) - { + { // get point location double point[3]; this->Points->GetPoint(pointId, point); if (polygon.Contains(vtkVector2f(point[0], point[1]))) - { + { this->Selection->InsertNextValue(pointId); - } } + } // return true if we selected any points return this->Selection->GetNumberOfTuples() > 0; @@ -505,12 +505,12 @@ template void SetBadPoints(T *data, vtkIdType n, std::set &bad) { for (vtkIdType i = 0; i < n; ++i) - { + { if (vtkMath::IsInf(data[i]) || vtkMath::IsNan(data[i])) - { + { bad.insert(i); - } } + } } // Calculate the bounds from the original data. @@ -520,10 +520,10 @@ void ComputeBounds(A *a, int n, double bounds[2]) bounds[0] = std::numeric_limits::max(); bounds[1] = -std::numeric_limits::max(); for (int i = 0; i < n; ++a, ++i) - { + { bounds[0] = bounds[0] < *a ? bounds[0] : *a; bounds[1] = bounds[1] > *a ? bounds[1] : *a; - } + } } template @@ -531,10 +531,10 @@ void ComputeBounds(A *a, int n, vtkIdTypeArray *bad, double bounds[2]) { // If possible, use the simpler code without any bad points. if (!bad || bad->GetNumberOfTuples() == 0) - { + { ComputeBounds(a, n, bounds); return; - } + } // Initialize the first range of points. vtkIdType start = 0; @@ -542,56 +542,56 @@ void ComputeBounds(A *a, int n, vtkIdTypeArray *bad, double bounds[2]) vtkIdType i = 0; vtkIdType nBad = bad->GetNumberOfTuples(); if (bad->GetValue(i) == 0) - { + { while (i < nBad && i == bad->GetValue(i)) - { + { start = bad->GetValue(i++) + 1; - } + } if (start < n) - { + { end = n; - } + } else - { + { // They are all bad points, return early. return; - } } + } if (i < nBad) - { + { end = bad->GetValue(i++); - } + } else - { + { end = n; - } + } bounds[0] = std::numeric_limits::max(); bounds[1] = -std::numeric_limits::max(); while (start < n) - { + { // Calculate the min/max in this range. while (start < end) - { + { bounds[0] = bounds[0] < a[start] ? bounds[0] : a[start]; bounds[1] = bounds[1] > a[start] ? bounds[1] : a[start]; ++start; - } + } // Now figure out the next range to be evaluated. start = end + 1; while (i < nBad && start == bad->GetValue(i)) - { + { start = bad->GetValue(i++) + 1; - } + } if (i < nBad) - { + { end = bad->GetValue(i++); - } + } else - { + { end = n; - } } + } } // Dispatch this call off to the right function. @@ -601,11 +601,11 @@ void ComputeBounds(A *a, vtkDataArray *b, int n, vtkIdTypeArray *bad, { ComputeBounds(a, n, bad, bounds); switch(b->GetDataType()) - { + { vtkTemplateMacro( ComputeBounds(static_cast(b->GetVoidPointer(0)), n, bad, &bounds[2])); - } + } } // Copy the two arrays into the points array @@ -615,10 +615,10 @@ void CopyToPoints(vtkPoints2D *points, A *a, B *b, int n, const vtkRectd &ss) points->SetNumberOfPoints(n); float* data = static_cast(points->GetVoidPointer(0)); for (int i = 0; i < n; ++i) - { + { data[2 * i] = static_cast((a[i] + ss[0]) * ss[2]); data[2 * i + 1] = static_cast((b[i] + ss[1]) * ss[3]); - } + } } // Copy one array into the points array, use the index of that array as x @@ -628,10 +628,10 @@ void CopyToPoints(vtkPoints2D *points, A *a, int n, const vtkRectd &ss) points->SetNumberOfPoints(n); float* data = static_cast(points->GetVoidPointer(0)); for (int i = 0; i < n; ++i) - { + { data[2 * i] = static_cast(( i + ss[0]) * ss[2]); data[2 * i + 1] = static_cast((a[i] + ss[1]) * ss[3]); - } + } } // Copy the two arrays into the points array @@ -640,11 +640,11 @@ void CopyToPointsSwitch(vtkPoints2D *points, A *a, vtkDataArray *b, int n, const vtkRectd &ss) { switch(b->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints( points, a, static_cast(b->GetVoidPointer(0)), n, ss)); - } + } } } @@ -653,9 +653,9 @@ void CopyToPointsSwitch(vtkPoints2D *points, A *a, vtkDataArray *b, int n, bool vtkPlotPoints::GetDataArrays(vtkTable *table, vtkDataArray *array[2]) { if (!table) - { + { return false; - } + } // Get the x and y arrays (index 0 and 1 respectively) array[0] = this->UseIndexForXSeries ? @@ -663,23 +663,23 @@ bool vtkPlotPoints::GetDataArrays(vtkTable *table, vtkDataArray *array[2]) array[1] = this->Data->GetInputArrayToProcess(1, table); if (!array[0] && !this->UseIndexForXSeries) - { + { vtkErrorMacro(<< "No X column is set (index 0)."); return false; - } + } else if (!array[1]) - { + { vtkErrorMacro(<< "No Y column is set (index 1)."); return false; - } + } else if (!this->UseIndexForXSeries && array[0]->GetNumberOfTuples() != array[1]->GetNumberOfTuples()) - { + { vtkErrorMacro("The x and y columns must have the same number of elements. " << array[0]->GetNumberOfTuples() << ", " << array[1]->GetNumberOfTuples()); return false; - } + } return true; } @@ -688,39 +688,39 @@ bool vtkPlotPoints::UpdateTableCache(vtkTable *table) { vtkDataArray *array[2] = { 0, 0 }; if (!this->GetDataArrays(table, array)) - { + { this->BuildTime.Modified(); return false; - } + } if (!this->Points) - { + { this->Points = vtkPoints2D::New(); - } + } vtkDataArray *x = array[0]; vtkDataArray *y = array[1]; // Now copy the components into their new columns if (this->UseIndexForXSeries) - { + { switch(y->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints( this->Points, static_cast(y->GetVoidPointer(0)), y->GetNumberOfTuples(), this->ShiftScale)); - } } + } else - { + { switch(x->GetDataType()) - { + { vtkTemplateMacro( CopyToPointsSwitch( this->Points, static_cast(x->GetVoidPointer(0)), y, x->GetNumberOfTuples(), this->ShiftScale)); - } } + } this->CalculateLogSeries(); this->FindBadPoints(); this->Points->Modified(); @@ -729,31 +729,31 @@ bool vtkPlotPoints::UpdateTableCache(vtkTable *table) // Additions for color mapping if (this->ScalarVisibility && !this->ColorArrayName.empty()) - { + { vtkDataArray* c = vtkArrayDownCast(table->GetColumnByName(this->ColorArrayName)); // TODO: Should add support for categorical coloring & try enum lookup if (c) - { + { if (!this->LookupTable) - { + { this->CreateDefaultLookupTable(); - } + } if (this->Colors) - { + { this->Colors->UnRegister(this); - } + } this->Colors = this->LookupTable->MapScalars(c, VTK_COLOR_MODE_MAP_SCALARS, -1); // Consistent register and unregisters this->Colors->Register(this); this->Colors->Delete(); - } + } else - { + { this->Colors->UnRegister(this); this->Colors = 0; - } } + } this->BuildTime.Modified(); @@ -766,78 +766,78 @@ void vtkPlotPoints::CalculateUnscaledInputBounds() vtkTable *table = this->Data->GetInput(); vtkDataArray *array[2] = { 0, 0 }; if (!this->GetDataArrays(table, array)) - { + { return; - } + } // Now copy the components into their new columns if (this->UseIndexForXSeries) - { + { this->UnscaledInputBounds[0] = 0.0; this->UnscaledInputBounds[1] = array[1]->GetNumberOfTuples() - 1; switch(array[1]->GetDataType()) - { + { vtkTemplateMacro( ComputeBounds(static_cast(array[1]->GetVoidPointer(0)), array[1]->GetNumberOfTuples(), this->BadPoints, &this->UnscaledInputBounds[2])); - } } + } else - { + { switch(array[0]->GetDataType()) - { + { vtkTemplateMacro( ComputeBounds(static_cast(array[0]->GetVoidPointer(0)), array[1], array[0]->GetNumberOfTuples(), this->BadPoints, this->UnscaledInputBounds)); - } } + } } //----------------------------------------------------------------------------- void vtkPlotPoints::CalculateLogSeries() { if (!this->XAxis || !this->YAxis) - { + { return; - } + } this->LogX = this->XAxis->GetLogScaleActive(); this->LogY = this->YAxis->GetLogScaleActive(); float* data = static_cast(this->Points->GetVoidPointer(0)); vtkIdType n = this->Points->GetNumberOfPoints(); if (this->LogX) - { + { if (this->XAxis->GetUnscaledMinimum() < 0.) - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i] = log10(fabs(data[2*i])); - } } + } else - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i] = log10(data[2*i]); - } } } + } if (this->LogY) - { + { if (this->YAxis->GetUnscaledMinimum() < 0.) - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i+1] = log10(fabs(data[2*i+1])); - } } + } else - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i+1] = log10(data[2*i+1]); - } } + } } } @@ -851,58 +851,58 @@ void vtkPlotPoints::FindBadPoints() vtkTable *table = this->Data->GetInput(); vtkDataArray *array[2] = { 0, 0 }; if (!this->GetDataArrays(table, array)) - { + { return; - } + } std::set bad; if (!this->UseIndexForXSeries) - { + { switch(array[0]->GetDataType()) - { + { vtkTemplateMacro( SetBadPoints(static_cast(array[0]->GetVoidPointer(0)), n, bad)); - } } + } switch(array[1]->GetDataType()) - { + { vtkTemplateMacro( SetBadPoints(static_cast(array[1]->GetVoidPointer(0)), n, bad)); - } + } // add points from the ValidPointMask if (this->ValidPointMask) - { + { for (vtkIdType i = 0; i < n; i++) - { + { if (this->ValidPointMask->GetValue(i) == 0) - { + { bad.insert(i); - } } } + } // If there are bad points copy them, if not ensure the pointer is null. if (!bad.empty()) - { + { if (!this->BadPoints) - { + { this->BadPoints = vtkIdTypeArray::New(); - } + } else - { + { this->BadPoints->SetNumberOfTuples(0); - } + } for (std::set::const_iterator it = bad.begin(); it != bad.end(); ++it) - { + { this->BadPoints->InsertNextValue(*it); - } } + } else if (this->BadPoints) - { + { this->BadPoints->Delete(); this->BadPoints = NULL; - } + } } //----------------------------------------------------------------------------- @@ -910,51 +910,51 @@ void vtkPlotPoints::CalculateBounds(double bounds[4]) { // We can use the BadPoints array to skip the bad points if (!this->Points) - { + { return; - } + } this->CalculateUnscaledInputBounds(); for (int i = 0; i < 4; ++i) - { + { bounds[i] = this->UnscaledInputBounds[i]; - } + } if (this->LogX) - { + { bounds[0] = log10(bounds[0]); bounds[1] = log10(bounds[1]); - } + } if (this->LogY) - { + { bounds[2] = log10(bounds[2]); bounds[3] = log10(bounds[3]); - } + } } //----------------------------------------------------------------------------- void vtkPlotPoints::SetLookupTable(vtkScalarsToColors *lut) { if ( this->LookupTable != lut ) - { + { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = lut; if (lut) - { + { lut->Register(this); - } - this->Modified(); } + this->Modified(); + } } //----------------------------------------------------------------------------- vtkScalarsToColors *vtkPlotPoints::GetLookupTable() { if ( this->LookupTable == 0 ) - { + { this->CreateDefaultLookupTable(); - } + } return this->LookupTable; } @@ -962,9 +962,9 @@ vtkScalarsToColors *vtkPlotPoints::GetLookupTable() void vtkPlotPoints::CreateDefaultLookupTable() { if ( this->LookupTable) - { + { this->LookupTable->UnRegister(this); - } + } this->LookupTable = vtkLookupTable::New(); // Consistent Register/UnRegisters. this->LookupTable->Register(this); @@ -976,23 +976,23 @@ void vtkPlotPoints::SelectColorArray(const vtkStdString& arrayName) { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "SelectColorArray called with no input table set."); return; - } + } if (this->ColorArrayName == arrayName) - { + { return; - } + } for (vtkIdType c = 0; c < table->GetNumberOfColumns(); ++c) - { + { if (arrayName == table->GetColumnName(c)) - { + { this->ColorArrayName = arrayName; this->Modified(); return; - } } + } vtkDebugMacro(<< "SelectColorArray called with invalid column name."); this->ColorArrayName = ""; this->Modified(); @@ -1004,30 +1004,30 @@ void vtkPlotPoints::SelectColorArray(vtkIdType arrayNum) { vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "SelectColorArray called with no input table set."); return; - } + } vtkDataArray *col = vtkArrayDownCast(table->GetColumn(arrayNum)); // TODO: Should add support for categorical coloring & try enum lookup if (!col) - { + { vtkDebugMacro(<< "SelectColorArray called with invalid column index"); return; - } + } else - { + { const char *arrayName = table->GetColumnName(arrayNum); if (this->ColorArrayName == arrayName || arrayName == 0) - { + { return; - } + } else - { + { this->ColorArrayName = arrayName; this->Modified(); - } } + } } //----------------------------------------------------------------------------- diff --git a/Charts/Core/vtkPlotPoints3D.cxx b/Charts/Core/vtkPlotPoints3D.cxx index cec5979ded1..71fbd19e8c8 100644 --- a/Charts/Core/vtkPlotPoints3D.cxx +++ b/Charts/Core/vtkPlotPoints3D.cxx @@ -49,63 +49,63 @@ void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent) bool vtkPlotPoints3D::Paint(vtkContext2D *painter) { if (!this->Visible || this->Points.size() == 0) - { + { return false; - } + } // Get the 3D context. vtkContext3D *context = painter->GetContext3D(); if (!context) - { + { return false; - } + } this->Update(); if (this->Points.size() > 0) - { + { // Draw the points in 3d. context->ApplyPen(this->Pen.GetPointer()); if (this->NumberOfComponents == 0) - { + { context->DrawPoints( this->Points[0].GetData(), static_cast(this->Points.size())); - } + } else - { + { context->DrawPoints( this->Points[0].GetData(), static_cast(this->Points.size()), this->Colors->GetPointer(0), this->NumberOfComponents); - } - } + } + // Now add some decorations for our selected points... if (this->Selection && this->Selection->GetNumberOfTuples()) - { + { if (this->Selection->GetMTime() > this->SelectedPointsBuildTime || this->GetMTime() > this->SelectedPointsBuildTime) - { + { size_t nSelected(static_cast(this->Selection->GetNumberOfTuples())); this->SelectedPoints.reserve(nSelected); for (size_t i = 0; i < nSelected; ++i) - { + { this->SelectedPoints.push_back(this->Points[this->Selection->GetValue(i)]); - } - this->SelectedPointsBuildTime.Modified(); } + this->SelectedPointsBuildTime.Modified(); + } // Now to render the selected points. if (!this->SelectedPoints.empty()) - { + { context->ApplyPen(this->SelectionPen.GetPointer()); context->DrawPoints(this->SelectedPoints[0].GetData(), static_cast(this->SelectedPoints.size())); - } } + } return true; } diff --git a/Charts/Core/vtkPlotStacked.cxx b/Charts/Core/vtkPlotStacked.cxx index 14ebcdf48e0..8da736c143d 100644 --- a/Charts/Core/vtkPlotStacked.cxx +++ b/Charts/Core/vtkPlotStacked.cxx @@ -45,13 +45,13 @@ namespace { bool compVector2fX(const vtkVector2f& v1, const vtkVector2f& v2) { if (v1.GetX() < v2.GetX()) - { + { return true; - } + } else - { + { return false; - } + } } // Copy the two arrays into the points array @@ -61,7 +61,7 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, B *b, { points->SetNumberOfPoints(n); for (int i = 0; i < n; ++i) - { + { double prev[] = {0.0,0.0}; if (previous_points) previous_points->GetPoint(i,prev); @@ -73,7 +73,7 @@ void CopyToPoints(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, B *b, bds[2] = bds[2] < yi ? bds[2] : yi; bds[3] = bds[3] > yi ? bds[3] : yi; - } + } } // Copy one array into the points array, use the index of that array as x @@ -85,7 +85,7 @@ void CopyToPoints( bds[1] = n - 1.; points->SetNumberOfPoints(n); for (int i = 0; i < n; ++i) - { + { double prev[] = {0.0,0.0}; if (previous_points) previous_points->GetPoint(i,prev); @@ -94,7 +94,7 @@ void CopyToPoints( bds[2] = bds[2] < yi ? bds[2] : yi; bds[3] = bds[3] > yi ? bds[3] : yi; - } + } } // Copy the two arrays into the points array @@ -103,11 +103,11 @@ void CopyToPointsSwitch(vtkPoints2D *points, vtkPoints2D *previous_points, A *a, vtkDataArray *b, int n, double bds[4]) { switch(b->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints(points,previous_points, a, static_cast(b->GetVoidPointer(0)), n, bds)); - } + } } } // namespace @@ -118,48 +118,48 @@ class vtkPlotStackedSegment : public vtkObject { static vtkPlotStackedSegment *New(); vtkPlotStackedSegment() - { + { this->Stacked = 0; this->Points = 0; this->BadPoints = 0; this->Previous = 0; this->Sorted = false; - } + } void Configure( vtkPlotStacked *stacked, vtkDataArray *x_array, vtkDataArray *y_array,vtkPlotStackedSegment *prev, double bds[4]) - { + { this->Stacked = stacked; this->Sorted = false; this->Previous = prev; if (!this->Points) - { + { this->Points = vtkSmartPointer::New(); - } + } if (x_array) - { + { switch (x_array->GetDataType()) - { + { vtkTemplateMacro( CopyToPointsSwitch(this->Points,this->Previous ? this->Previous->Points : 0, static_cast(x_array->GetVoidPointer(0)), y_array,x_array->GetNumberOfTuples(), bds)); - } } + } else - { // Using Index for X Series + { // Using Index for X Series switch (y_array->GetDataType()) - { + { vtkTemplateMacro( CopyToPoints(this->Points, this->Previous ? this->Previous->Points : 0, static_cast(y_array->GetVoidPointer(0)), y_array->GetNumberOfTuples(), bds)); - } } + } // Nothing works if we're not sorted on the X access vtkIdType n = this->Points->GetNumberOfPoints(); @@ -170,17 +170,17 @@ class vtkPlotStackedSegment : public vtkObject { this->CalculateLogSeries(); this->FindBadPoints(); - } + } void CalculateLogSeries() - { + { vtkAxis *xAxis = this->Stacked->GetXAxis(); vtkAxis *yAxis = this->Stacked->GetYAxis(); if (!xAxis || !yAxis) - { + { return; - } + } bool logX = xAxis->GetLogScaleActive(); bool logY = yAxis->GetLogScaleActive(); @@ -189,106 +189,106 @@ class vtkPlotStackedSegment : public vtkObject { vtkIdType n = this->Points->GetNumberOfPoints(); if (logX) - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i] = log10(data[2*i]); - } } + } if (logY) - { + { for (vtkIdType i = 0; i < n; ++i) - { + { data[2*i+1] = log10(data[2*i+1]); - } } } + } void FindBadPoints() - { + { // This should be run after CalculateLogSeries as a final step. float* data = static_cast(this->Points->GetVoidPointer(0)); vtkIdType n = this->Points->GetNumberOfPoints(); if (!this->BadPoints) - { + { this->BadPoints = vtkSmartPointer::New(); - } + } else - { + { this->BadPoints->SetNumberOfTuples(0); - } + } // Scan through and find any bad points. for (vtkIdType i = 0; i < n; ++i) - { + { vtkIdType p = 2*i; if (vtkMath::IsInf(data[p]) || vtkMath::IsInf(data[p+1]) || vtkMath::IsNan(data[p]) || vtkMath::IsNan(data[p+1])) - { + { this->BadPoints->InsertNextValue(i); - } } + } if (this->BadPoints->GetNumberOfTuples() == 0) - { + { this->BadPoints = 0; - } } + } void GetBounds(double bounds[4]) - { + { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; if (this->Points) - { + { if (!this->BadPoints) - { + { this->Points->GetBounds(bounds); - } + } else - { + { // There are bad points in the series - need to do this ourselves. this->CalculateBounds(bounds); - } } } + } void CalculateBounds(double bounds[4]) - { + { // We can use the BadPoints array to skip the bad points if (!this->Points || !this->BadPoints) - { + { return; - } + } vtkIdType start = 0; vtkIdType end = 0; vtkIdType i = 0; vtkIdType nBad = this->BadPoints->GetNumberOfTuples(); vtkIdType nPoints = this->Points->GetNumberOfPoints(); if (this->BadPoints->GetValue(i) == 0) - { + { while (i < nBad && i == this->BadPoints->GetValue(i)) - { + { start = this->BadPoints->GetValue(i++) + 1; - } + } if (start < nPoints) - { + { end = nPoints; - } + } else - { + { // They are all bad points return; - } } + } if (i < nBad) - { + { end = this->BadPoints->GetValue(i++); - } + } else - { + { end = nPoints; - } + } vtkVector2f* pts = static_cast(this->Points->GetVoidPointer(0)); // Initialize our min/max @@ -296,45 +296,45 @@ class vtkPlotStackedSegment : public vtkObject { bounds[2] = bounds[3] = pts[start++].GetY(); while (start < nPoints) - { + { // Calculate the min/max in this range while (start < end) - { + { float x = pts[start].GetX(); float y = pts[start++].GetY(); if (x < bounds[0]) - { + { bounds[0] = x; - } + } else if (x > bounds[1]) - { + { bounds[1] = x; - } + } if (y < bounds[2]) - { + { bounds[2] = y; - } + } else if (y > bounds[3]) - { + { bounds[3] = y; - } } + } // Now figure out the next range start = end + 1; if (++i < nBad) - { + { end = this->BadPoints->GetValue(i); - } + } else - { + { end = nPoints; - } } } + } void Paint(vtkContext2D *painter, vtkPen *pen, vtkBrush *brush) - { + { painter->ApplyPen(pen); painter->ApplyBrush(brush); int n = this->Points->GetNumberOfPoints(); @@ -344,51 +344,51 @@ class vtkPlotStackedSegment : public vtkObject { data_base = vtkArrayDownCast(this->Previous->Points->GetData())->GetPointer(0); if (n >= 2) - { + { float poly_points[8]; for (int i = 0; i < (n - 1); ++i) - { + { if (data_base) - { + { poly_points[0] = data_base[2*i]; poly_points[1] = data_base[2*i+1]; poly_points[2] = data_base[2*i+2]; poly_points[3] = data_base[2*i+3]; - } + } else - { + { poly_points[0] = data_extent[2*i]; // Use the same X as extent poly_points[1] = 0.0; poly_points[2] = data_extent[2*i+2]; // Use the same X as extent poly_points[3] = 0.0; - } + } poly_points[4] = data_extent[2*i+2]; poly_points[5] = data_extent[2*i+3]; poly_points[6] = data_extent[2*i]; poly_points[7] = data_extent[2*i+1]; painter->DrawQuad(poly_points); - } } } + } bool GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location) - { + { // Right now doing a simple bisector search of the array. This should be // revisited. Assumes the x axis is sorted, which should always be true for // line plots. if (!this->Points) - { + { return false; - } + } vtkIdType n = this->Points->GetNumberOfPoints(); if (n < 2) - { + { return false; - } + } // Set up our search array, use the STL lower_bound algorithm // When searching, invert the behavior of the offset and @@ -406,48 +406,48 @@ class vtkPlotStackedSegment : public vtkObject { // to the base because each segment is called in order and the // first positive wins. while (low != v.end()) - { + { if (low->GetX() - tol.GetX() > point.GetX()) - { + { break; - } + } else if (low->GetX()-tol.GetX() < point.GetX() && low->GetX()+tol.GetX() > point.GetX()) - { + { if ((point.GetY() >= 0 && point.GetY() < low->GetY()) || (point.GetY() < 0 && point.GetY() > low->GetY())) - { + { *location = *low; return true; - } } - ++low; } - return false; + ++low; } + return false; + } void SelectPoints(const vtkVector2f& min, const vtkVector2f& max, vtkIdTypeArray *selection) - { + { if (!this->Points) - { + { return; - } + } // Iterate through all points and check whether any are in range vtkVector2f* data = static_cast(this->Points->GetVoidPointer(0)); vtkIdType n = this->Points->GetNumberOfPoints(); for (vtkIdType i = 0; i < n; ++i) - { + { if (data[i].GetX() >= min.GetX() && data[i].GetX() <= max.GetX() && data[i].GetY() >= min.GetY() && data[i].GetY() <= max.GetY()) - { + { selection->InsertNextValue(i); - } } } + } vtkSmartPointer Previous; vtkSmartPointer Points; @@ -464,93 +464,93 @@ class vtkPlotStackedPrivate { public: vtkPlotStackedPrivate(vtkPlotStacked *stacked) : Stacked(stacked) {} void Update() - { + { this->Segments.clear(); this->UnscaledInputBounds[0] = this->UnscaledInputBounds[2] = vtkMath::Inf(); this->UnscaledInputBounds[1] = this->UnscaledInputBounds[3] = -vtkMath::Inf(); - } + } vtkPlotStackedSegment *AddSegment(vtkDataArray *x_array, vtkDataArray *y_array, vtkPlotStackedSegment *prev=0) - { + { vtkSmartPointer segment = vtkSmartPointer::New(); segment->Configure(this->Stacked,x_array,y_array,prev,this->UnscaledInputBounds); this->Segments.push_back(segment); return segment; - } + } void PaintSegments(vtkContext2D *painter, vtkColorSeries *colorSeries, vtkPen *pen, vtkBrush *brush) - { + { int colorInSeries = 0; bool useColorSeries = this->Segments.size() > 1; for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { if (useColorSeries && colorSeries) brush->SetColor(colorSeries->GetColorRepeating(colorInSeries++).GetData()); (*it)->Paint(painter,pen,brush); - } } + } vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tol, vtkVector2f* location) - { + { // Depends on the fact that we check the segments in order. Each // Segment only worrys about its own total extent from the base. int index = 0; for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { if ((*it)->GetNearestPoint(point,tol,location)) - { + { return index; - } - ++index; } - return -1; + ++index; } + return -1; + } void GetBounds(double bounds[4]) - { + { // Depends on the fact that we check the segments in order. Each // Segment only worrys about its own total extent from the base. double segment_bounds[4]; for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { (*it)->GetBounds(segment_bounds); if (segment_bounds[0] < bounds[0]) - { + { bounds[0] = segment_bounds[0]; - } + } if (segment_bounds[1] > bounds[1]) - { + { bounds[1] = segment_bounds[1]; - } + } if (segment_bounds[2] < bounds[2]) - { + { bounds[2] = segment_bounds[2]; - } + } if (segment_bounds[3] > bounds[3]) - { + { bounds[3] = segment_bounds[3]; - } } } + } void SelectPoints(const vtkVector2f& min, const vtkVector2f& max, vtkIdTypeArray *selection) - { + { for (std::vector >::iterator it = this->Segments.begin(); it != this->Segments.end(); ++it) - { + { (*it)->SelectPoints(min,max,selection); - } } + } std::vector > Segments; vtkPlotStacked *Stacked; @@ -577,15 +577,15 @@ vtkPlotStacked::vtkPlotStacked() vtkPlotStacked::~vtkPlotStacked() { if (this->BaseBadPoints) - { + { this->BaseBadPoints->Delete(); this->BaseBadPoints = NULL; - } + } if (this->ExtentBadPoints) - { + { this->ExtentBadPoints->Delete(); this->ExtentBadPoints = NULL; - } + } delete this->Private; } @@ -614,32 +614,32 @@ void vtkPlotStacked::GetColor(double rgb[3]) void vtkPlotStacked::Update() { if (!this->Visible) - { + { return; - } + } // Check if we have an input vtkTable *table = this->Data->GetInput(); if (!table) - { + { vtkDebugMacro(<< "Update event called with no input table set."); return; - } + } else if(this->Data->GetMTime() > this->BuildTime || table->GetMTime() > this->BuildTime || this->MTime > this->BuildTime) - { + { vtkDebugMacro(<< "Updating cached values."); this->UpdateTableCache(table); - } + } else if ((this->XAxis->GetMTime() > this->BuildTime) || (this->YAxis->GetMTime() > this->BuildTime)) - { + { if (this->LogX != this->XAxis->GetLogScaleActive() || this->LogY != this->YAxis->GetLogScaleActive()) - { + { this->UpdateTableCache(table); - } } + } } //----------------------------------------------------------------------------- @@ -649,19 +649,19 @@ bool vtkPlotStacked::Paint(vtkContext2D *painter) vtkDebugMacro(<< "Paint event called in vtkPlotStacked."); if (!this->Visible) - { + { return false; - } + } // Now add some decorations for our selected points... if (this->Selection) - { + { vtkDebugMacro(<<"Selection set " << this->Selection->GetNumberOfTuples()); - } + } else - { + { vtkDebugMacro("No selection set."); - } + } this->Private->PaintSegments(painter,this->ColorSeries,this->Pen,this->Brush); @@ -673,19 +673,19 @@ bool vtkPlotStacked::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, int legendIndex) { if (this->ColorSeries) - { + { vtkNew pen; vtkNew brush; pen->SetColor(this->ColorSeries->GetColorRepeating(legendIndex).GetData()); brush->SetColor(pen->GetColor()); painter->ApplyPen(pen.GetPointer()); painter->ApplyBrush(brush.GetPointer()); - } + } else - { + { painter->ApplyPen(this->Pen); painter->ApplyBrush(this->Brush); - } + } painter->DrawRect(rect[0], rect[1], rect[2], rect[3]); return true; } @@ -700,9 +700,9 @@ void vtkPlotStacked::GetBounds(double bounds[4]) void vtkPlotStacked::GetUnscaledInputBounds(double bounds[4]) { for (int i = 0; i < 4; ++i) - { + { bounds[i] = this->Private->UnscaledInputBounds[i]; - } + } } //----------------------------------------------------------------------------- @@ -717,9 +717,9 @@ vtkIdType vtkPlotStacked::GetNearestPoint(const vtkVector2f& point, bool vtkPlotStacked::SelectPoints(const vtkVector2f& min, const vtkVector2f& max) { if (!this->Selection) - { + { this->Selection = vtkIdTypeArray::New(); - } + } this->Selection->SetNumberOfTuples(0); this->Private->SelectPoints(min,max,this->Selection); @@ -732,30 +732,30 @@ vtkStringArray *vtkPlotStacked::GetLabels() { // If the label string is empty, return the y column name if (this->Labels) - { + { return this->Labels; - } + } else if (this->AutoLabels) - { + { return this->AutoLabels; - } + } else if (this->Data->GetInput() && this->Data->GetInputArrayToProcess(1, this->Data->GetInput())) - { + { this->AutoLabels = vtkSmartPointer::New(); this->AutoLabels->InsertNextValue(this->Data->GetInputArrayToProcess(1, this->Data->GetInput())->GetName()); std::map< int, std::string >::iterator it; for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it ) - { + { this->AutoLabels->InsertNextValue((*it).second); - } - return this->AutoLabels; } + return this->AutoLabels; + } else - { + { return NULL; - } + } } //----------------------------------------------------------------------------- @@ -767,27 +767,27 @@ bool vtkPlotStacked::UpdateTableCache(vtkTable *table) vtkDataArray* y = this->Data->GetInputArrayToProcess(1, table); if (!x && !this->UseIndexForXSeries) - { + { vtkErrorMacro(<< "No X column is set (index 0)."); this->BuildTime.Modified(); return false; - } + } else if (!y) - { + { vtkErrorMacro(<< "No Y column is set (index 1)."); this->BuildTime.Modified(); return false; - } + } else if (!this->UseIndexForXSeries && x->GetNumberOfTuples() != y->GetNumberOfTuples()) - { + { vtkErrorMacro("The x and y columns must have the same number of elements. " << x->GetNumberOfTuples() << ", " << y->GetNumberOfTuples() << ", " << y->GetNumberOfTuples() ); this->BuildTime.Modified(); return false; - } + } this->Private->Update(); vtkPlotStackedSegment *prev = this->Private->AddSegment(x,y); @@ -795,10 +795,10 @@ bool vtkPlotStacked::UpdateTableCache(vtkTable *table) std::map< int, std::string >::iterator it; for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it ) - { + { y = vtkArrayDownCast(table->GetColumnByName((*it).second.c_str())); prev = this->Private->AddSegment(x,y,prev); - } + } // Record if this update was done with Log scale. this->LogX = this->XAxis ? this->XAxis->GetLogScaleActive(): false; @@ -819,13 +819,13 @@ void vtkPlotStacked::PrintSelf(ostream &os, vtkIndent indent) void vtkPlotStacked::SetInputArray(int index, const vtkStdString &name) { if (index == 0 || index == 1) - { + { vtkPlot::SetInputArray(index,name); - } + } else - { + { this->Private->AdditionalSeries[index] = name; - } + } this->AutoLabels = 0; // No longer valid } @@ -833,9 +833,9 @@ void vtkPlotStacked::SetInputArray(int index, const vtkStdString &name) void vtkPlotStacked::SetColorSeries(vtkColorSeries *colorSeries) { if (this->ColorSeries == colorSeries) - { + { return; - } + } this->ColorSeries = colorSeries; this->Modified(); } diff --git a/Charts/Core/vtkPlotSurface.cxx b/Charts/Core/vtkPlotSurface.cxx index 003e2dc2d09..6c016def158 100644 --- a/Charts/Core/vtkPlotSurface.cxx +++ b/Charts/Core/vtkPlotSurface.cxx @@ -56,33 +56,33 @@ void vtkPlotSurface::PrintSelf(ostream &os, vtkIndent indent) bool vtkPlotSurface::Paint(vtkContext2D *painter) { if (!this->Visible) - { + { return false; - } + } if (!this->DataHasBeenRescaled) - { + { this->RescaleData(); - } + } // Get the 3D context. vtkContext3D *context = painter->GetContext3D(); if (!context) - { + { return false; - } + } context->ApplyPen(this->Pen.GetPointer()); // draw the surface if (this->Surface.size() > 0) - { + { context->DrawTriangleMesh(this->Surface[0].GetData(), static_cast(this->Surface.size()), this->Colors->GetPointer(0), this->ColorComponents); - } + } return true; } @@ -99,13 +99,13 @@ void vtkPlotSurface::SetInputData(vtkTable *input) // initialize data ranges to row and column indices if they are not // already set. if (this->XMinimum == 0 && this->XMaximum == 0) - { + { this->XMaximum = this->NumberOfColumns - 1; - } + } if (this->YMinimum == 0 && this->YMaximum == 0) - { + { this->YMaximum = this->NumberOfRows - 1; - } + } this->Points.clear(); this->Points.resize(this->NumberOfRows * this->NumberOfColumns); @@ -114,9 +114,9 @@ void vtkPlotSurface::SetInputData(vtkTable *input) float surfaceMin = VTK_FLOAT_MAX; float surfaceMax = VTK_FLOAT_MIN; for (int i = 0; i < this->NumberOfRows; ++i) - { + { for (int j = 0; j < this->NumberOfColumns; ++j) - { + { // X (columns) data[pos] = this->ColumnToX(j); ++pos; @@ -131,20 +131,20 @@ void vtkPlotSurface::SetInputData(vtkTable *input) ++pos; if (k < surfaceMin) - { + { surfaceMin = k; - } + } if (k > surfaceMax) - { + { surfaceMax = k; - } } } + } if (this->Chart) - { + { this->Chart->RecalculateBounds(); - } + } this->ComputeDataBounds(); // setup lookup table @@ -203,9 +203,9 @@ void vtkPlotSurface::GenerateSurface() float *data = this->Surface[0].GetData(); int pos = 0; for (int i = 0; i < this->NumberOfRows - 1; ++i) - { + { for (int j = 0; j < this->NumberOfColumns - 1; ++j) - { + { float value1 = this->InputTable->GetValue(i, j).ToFloat(); float value2 = this->InputTable->GetValue(i, j + 1).ToFloat(); float value3 = this->InputTable->GetValue(i + 1, j + 1).ToFloat(); @@ -220,8 +220,8 @@ void vtkPlotSurface::GenerateSurface() this->InsertSurfaceVertex(data, value1, i, j, pos); this->InsertSurfaceVertex(data, value3, i + 1, j + 1, pos); this->InsertSurfaceVertex(data, value4, i + 1, j, pos); - } } + } } //----------------------------------------------------------------------------- @@ -266,9 +266,9 @@ void vtkPlotSurface::RescaleData() // rescale Points (used by ChartXYZ to generate axes scales). int pos = 0; for (int i = 0; i < this->NumberOfRows; ++i) - { + { for (int j = 0; j < this->NumberOfColumns; ++j) - { + { // X (columns) data[pos] = this->ColumnToX(j); ++pos; @@ -279,8 +279,8 @@ void vtkPlotSurface::RescaleData() // Z value doesn't change ++pos; - } } + } this->Chart->RecalculateBounds(); this->ComputeDataBounds(); this->DataHasBeenRescaled = true; diff --git a/Charts/Core/vtkScalarsToColorsItem.cxx b/Charts/Core/vtkScalarsToColorsItem.cxx index fce10c41e07..69d898520e9 100644 --- a/Charts/Core/vtkScalarsToColorsItem.cxx +++ b/Charts/Core/vtkScalarsToColorsItem.cxx @@ -59,25 +59,25 @@ vtkScalarsToColorsItem::vtkScalarsToColorsItem() vtkScalarsToColorsItem::~vtkScalarsToColorsItem() { if (this->PolyLinePen) - { + { this->PolyLinePen->Delete(); this->PolyLinePen = 0; - } + } if (this->Texture) - { + { this->Texture->Delete(); this->Texture = 0; - } + } if (this->Shape) - { + { this->Shape->Delete(); this->Shape = 0; - } + } if (this->Callback) - { + { this->Callback->Delete(); this->Callback = 0; - } + } } //----------------------------------------------------------------------------- @@ -92,13 +92,13 @@ void vtkScalarsToColorsItem::GetBounds(double bounds[4]) { if (this->UserBounds[1] > this->UserBounds[0] && this->UserBounds[3] > this->UserBounds[2]) - { + { bounds[0] = this->UserBounds[0]; bounds[1] = this->UserBounds[1]; bounds[2] = this->UserBounds[2]; bounds[3] = this->UserBounds[3]; return; - } + } this->ComputeBounds(bounds); } @@ -117,13 +117,13 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter) this->TextureWidth = this->GetScene()->GetViewWidth(); if (this->Texture == 0 || this->Texture->GetMTime() < this->GetMTime()) - { + { this->ComputeTexture(); - } + } if (this->Texture == 0) - { + { return false; - } + } vtkSmartPointer transparentPen = vtkSmartPointer::New(); transparentPen->SetLineType(vtkPen::NO_PEN); painter->ApplyPen(transparentPen); @@ -135,7 +135,7 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter) vtkBrush::Stretch); const int size = this->Shape->GetNumberOfPoints(); if (!this->MaskAboveCurve || size < 2) - { + { double dbounds[4]; this->GetBounds(dbounds); @@ -150,9 +150,9 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter) fbounds[0], fbounds[3], fbounds[1], fbounds[3], fbounds[1], fbounds[2]); - } + } else - { + { const vtkRectd& ss = this->ShiftScale; vtkPoints2D* trapezoids = vtkPoints2D::New(); @@ -160,7 +160,7 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter) double point[2]; vtkIdType j = -1; for (vtkIdType i = 0; i < size; ++i) - { + { this->Shape->GetPoint(i, point); // shift/scale to scale from data space to rendering space. @@ -168,29 +168,29 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter) point[1] = (point[1] + ss[1]) * ss[3]; trapezoids->SetPoint(++j, point[0], 0.); trapezoids->SetPoint(++j, point); - } + } painter->DrawQuadStrip(trapezoids); trapezoids->Delete(); - } + } if (this->PolyLinePen->GetLineType() != vtkPen::NO_PEN) - { + { const vtkRectd& ss = this->ShiftScale; vtkNew transformedShape; transformedShape->SetNumberOfPoints(size); for (vtkIdType i = 0; i < size; ++i) - { + { double point[2]; this->Shape->GetPoint(i, point); // shift/scale to scale from data space to rendering space. point[0] = (point[0] + ss[0]) * ss[2]; point[1] = (point[1] + ss[1]) * ss[3]; transformedShape->SetPoint(i, point); - } + } painter->ApplyPen(this->PolyLinePen); painter->DrawPoly(transformedShape.GetPointer()); - } + } return true; } diff --git a/Charts/Core/vtkScatterPlotMatrix.cxx b/Charts/Core/vtkScatterPlotMatrix.cxx index abb7781cfd0..d5c04cf8268 100644 --- a/Charts/Core/vtkScatterPlotMatrix.cxx +++ b/Charts/Core/vtkScatterPlotMatrix.cxx @@ -136,14 +136,14 @@ class vtkScatterPlotMatrix::PIMPL void UpdateAxis(vtkAxis* axis, pimplChartSetting* setting, bool updateLabel = true) - { + { if(axis && setting) - { + { axis->GetPen()->SetColor(setting->AxisColor); axis->GetGridPen()->SetColor(setting->GridColor); axis->SetGridVisible(setting->ShowGrid); if (updateLabel) - { + { vtkTextProperty *prop = setting->LabelFont.GetPointer(); axis->SetNotation(setting->LabelNotation); axis->SetPrecision(setting->LabelPrecision); @@ -155,22 +155,22 @@ class vtkScatterPlotMatrix::PIMPL prop->GetFontFamilyAsString()); axis->GetLabelProperties()->SetBold(prop->GetBold()); axis->GetLabelProperties()->SetItalic(prop->GetItalic()); - } } } + } void UpdateChart(vtkChart* chart, pimplChartSetting* setting) - { + { if(chart && setting) - { + { vtkPlot *plot = chart->GetPlot(0); if (plot) - { + { plot->SetTooltipNotation(setting->TooltipNotation); plot->SetTooltipPrecision(setting->TooltipPrecision); - } } } + } vtkNew Histogram; bool VisibleColumnsModified; @@ -215,67 +215,67 @@ bool PopulateHistograms(vtkTable *input, vtkTable *output, vtkStringArray *s, // The output table will have the twice the number of columns, they will be // the x and y for input column. This is the bin centers, and the population. for (vtkIdType i = 0; i < s->GetNumberOfTuples(); ++i) - { + { double minmax[2] = { 0.0, 0.0 }; vtkStdString name(s->GetValue(i)); vtkDataArray *in = vtkArrayDownCast(input->GetColumnByName(name.c_str())); if (in) - { + { // The bin values are the centers, extending +/- half an inc either side in->GetRange(minmax); if (minmax[0] == minmax[1]) - { + { minmax[1] = minmax[0] + 1.0; - } + } double inc = (minmax[1] - minmax[0]) / (NumberOfBins) * 1.001; double halfInc = inc / 2.0; vtkSmartPointer extents = vtkArrayDownCast( output->GetColumnByName(vtkStdString(name + "_extents").c_str())); if (!extents) - { + { extents = vtkSmartPointer::New(); extents->SetName(vtkStdString(name + "_extents").c_str()); - } + } extents->SetNumberOfTuples(NumberOfBins); float *centers = static_cast(extents->GetVoidPointer(0)); double min = minmax[0] - 0.0005 * inc + halfInc; for (int j = 0; j < NumberOfBins; ++j) - { + { extents->SetValue(j, min + j * inc); - } + } vtkSmartPointer populations = vtkArrayDownCast( output->GetColumnByName(vtkStdString(name + "_pops").c_str())); if (!populations) - { + { populations = vtkSmartPointer::New(); populations->SetName(vtkStdString(name + "_pops").c_str()); - } + } populations->SetNumberOfTuples(NumberOfBins); int *pops = static_cast(populations->GetVoidPointer(0)); for (int k = 0; k < NumberOfBins; ++k) - { + { pops[k] = 0; - } + } for (vtkIdType j = 0; j < in->GetNumberOfTuples(); ++j) - { + { double v(0.0); in->GetTuple(j, &v); for (int k = 0; k < NumberOfBins; ++k) - { + { if (vtkMathUtilities::FuzzyCompare(v, double(centers[k]), halfInc)) - { + { ++pops[k]; break; - } } } + } output->AddColumn(extents.GetPointer()); output->AddColumn(populations.GetPointer()); - } } + } return true; } @@ -283,69 +283,69 @@ bool MoveColumn(vtkStringArray* visCols, int fromCol, int toCol) { if(!visCols || visCols->GetNumberOfTuples() == 0 || fromCol == toCol || fromCol == (toCol-1) || fromCol < 0 || toCol < 0) - { + { return false; - } + } int numCols = visCols->GetNumberOfTuples(); if( fromCol >= numCols || toCol > numCols) - { + { return false; - } + } std::vector newVisCols; vtkIdType c; if(toCol == numCols) - { + { for(c=0; cGetValue(c)); - } } + } // move the fromCol to the end newVisCols.push_back(visCols->GetValue(fromCol)); - } + } // insert the fromCol before toCol else if(fromCol < toCol) - { + { // move Cols in the middle up for(c=0; cGetValue(c)); - } + } for(c=fromCol+1; cGetValue(fromCol)); - } - newVisCols.push_back(visCols->GetValue(c)); } + newVisCols.push_back(visCols->GetValue(c)); } + } else - { + { for(c=0; cGetValue(c)); - } + } newVisCols.push_back(visCols->GetValue(fromCol)); for(c=toCol; cGetValue(c)); - } } } + } // repopulate the visCols vtkIdType visId=0; std::vector::iterator arrayIt; for(arrayIt=newVisCols.begin(); arrayIt!=newVisCols.end(); ++arrayIt) - { + { visCols->SetValue(visId++, *arrayIt); - } + } return true; } } // End of anonymous namespace @@ -370,7 +370,7 @@ vtkScatterPlotMatrix::~vtkScatterPlotMatrix() void vtkScatterPlotMatrix::Update() { if (this->Private->VisibleColumnsModified) - { + { // We need to handle layout changes due to modified visibility. // Build up our histograms data before updating the layout. PopulateHistograms(this->Input.GetPointer(), @@ -379,11 +379,11 @@ void vtkScatterPlotMatrix::Update() this->NumberOfBins); this->UpdateLayout(); this->Private->VisibleColumnsModified = false; - } + } else if (this->GetMTime() > this->LayoutUpdatedTime) - { + { this->UpdateLayout(); - } + } } bool vtkScatterPlotMatrix::Paint(vtkContext2D *painter) @@ -406,7 +406,7 @@ bool vtkScatterPlotMatrix::SetActivePlot(const vtkVector2i &pos) { if (pos.GetX() + pos.GetY() + 1 < this->Size.GetX() && pos.GetX() < this->Size.GetX() && pos.GetY() < this->Size.GetY()) - { + { // The supplied index is valid (in the lower quadrant). this->ActivePlot = pos; @@ -415,53 +415,53 @@ bool vtkScatterPlotMatrix::SetActivePlot(const vtkVector2i &pos) // set background colors for plots if (this->GetChart(this->ActivePlot)->GetPlot(0)) - { + { int plotCount = this->GetSize().GetX(); for (int i = 0; i < plotCount; ++i) - { + { for (int j = 0; j < plotCount; ++j) - { + { if (this->GetPlotType(i, j) == SCATTERPLOT) - { + { vtkChartXY *chart = vtkChartXY::SafeDownCast(this->GetChart(vtkVector2i(i, j))); if (pos[0] == i && pos[1] == j) - { + { // set the new active chart background color to light green chart->SetBackgroundBrush( this->Private->SelectedChartBGBrush.GetPointer()); - } + } else if (pos[0] == i || pos[1] == j) - { + { // set background color for all other charts in the selected // chart's row and column to light red chart->SetBackgroundBrush( this->Private->SelectedRowColumnBGBrush.GetPointer()); - } + } else - { + { // set all else to white chart->SetBackgroundBrush( this->Private->ChartSettings[SCATTERPLOT] ->BackgroundBrush.GetPointer()); - } } } } } + } if (this->Private->BigChart) - { + { vtkPlot *plot = this->Private->BigChart->GetPlot(0); vtkStdString column = this->GetColumnName(pos.GetX()); vtkStdString row = this->GetRowName(pos.GetY()); if (!plot) - { + { plot = this->Private->BigChart->AddPlot(vtkChart::POINTS); vtkChart *active = this->GetChart(this->ActivePlot); vtkChartXY *xy = vtkChartXY::SafeDownCast(this->Private->BigChart); if (xy) - { + { // Set plot corner, and axis visibility xy->SetPlotCorner(plot, 2); xy->SetAutoAxes(false); @@ -478,38 +478,38 @@ bool vtkScatterPlotMatrix::SetActivePlot(const vtkVector2i &pos) // set labels array if(this->Private->IndexedLabelsArray) - { + { plot->SetIndexedLabels(this->Private->IndexedLabelsArray); plot->SetTooltipLabelFormat("%i"); - } } + } if (xy && active) - { + { vtkAxis *a = active->GetAxis(vtkAxis::BOTTOM); xy->GetAxis(vtkAxis::TOP)->SetUnscaledRange( a->GetUnscaledMinimum(), a->GetUnscaledMaximum()); a = active->GetAxis(vtkAxis::LEFT); xy->GetAxis(vtkAxis::RIGHT)->SetUnscaledRange( a->GetUnscaledMinimum(), a->GetUnscaledMaximum()); - } } + } else - { + { this->Private->BigChart->ClearPlots(); plot = this->Private->BigChart->AddPlot(vtkChart::POINTS); vtkChartXY *xy = vtkChartXY::SafeDownCast(this->Private->BigChart); if (xy) - { + { xy->SetPlotCorner(plot, 2); - } + } // set labels array if(this->Private->IndexedLabelsArray) - { + { plot->SetIndexedLabels(this->Private->IndexedLabelsArray); plot->SetTooltipLabelFormat("%i"); - } } + } plot->SetInputData(this->Input.GetPointer(), column, row); plot->SetPen(this->Private->ChartSettings[ACTIVEPLOT] ->PlotPen.GetPointer()); @@ -531,13 +531,13 @@ bool vtkScatterPlotMatrix::SetActivePlot(const vtkVector2i &pos) this->VisibleColumns->GetValue(this->GetSize().GetX() - pos.GetY() - 1)); // Calculate the ideal range. //this->Private->BigChart->RecalculateBounds(); - } - return true; } + return true; + } else - { + { return false; - } + } } vtkVector2i vtkScatterPlotMatrix::GetActivePlot() @@ -550,67 +550,67 @@ void vtkScatterPlotMatrix::UpdateAnimationPath(const vtkVector2i& newActivePos) this->Private->AnimationPath.clear(); if (newActivePos[0] != this->ActivePlot[0] || newActivePos[1] != this->ActivePlot[1]) - { + { if (newActivePos[1] >= this->ActivePlot[1]) - { + { // x direction first if (this->ActivePlot[0]>newActivePos[0]) - { + { for(int r = this->ActivePlot[0] - 1; r >= newActivePos[0]; r--) - { + { this->Private->AnimationPath.push_back(vtkVector2i(r, this->ActivePlot[1])); - } } + } else - { + { for (int r = this->ActivePlot[0] + 1; r <= newActivePos[0]; r++) - { + { this->Private->AnimationPath.push_back(vtkVector2i(r, this->ActivePlot[1])); - } } + } // then y direction for (int c = this->ActivePlot[1] + 1; c <= newActivePos[1]; c++) - { + { this->Private->AnimationPath.push_back(vtkVector2i(newActivePos[0], c)); - } } + } else - { + { // y direction first for (int c = this->ActivePlot[1] - 1; c >= newActivePos[1]; c--) - { + { this->Private->AnimationPath.push_back(vtkVector2i(this->ActivePlot[0], c)); - } + } // then x direction if (this->ActivePlot[0]>newActivePos[0]) - { + { for (int r = this->ActivePlot[0] - 1; r >= newActivePos[0]; r--) - { + { this->Private->AnimationPath.push_back(vtkVector2i(r, newActivePos[1])); - } } + } else - { + { for (int r = this->ActivePlot[0] + 1; r <= newActivePos[0]; r++) - { + { this->Private->AnimationPath.push_back(vtkVector2i(r, newActivePos[1])); - } } } } + } } void vtkScatterPlotMatrix::StartAnimation(vtkRenderWindowInteractor* interactor) { // Start a simple repeating timer to advance along the path until completion. if (!this->Private->TimerCallbackInitialized && interactor) - { + { if (!this->Private->AnimationCallbackInitialized) - { + { this->Private->AnimationCallback->SetClientData(this); this->Private->AnimationCallback->SetCallback( vtkScatterPlotMatrix::ProcessEvents); @@ -619,13 +619,13 @@ void vtkScatterPlotMatrix::StartAnimation(vtkRenderWindowInteractor* interactor) 0); this->Private->Interactor = interactor; this->Private->AnimationCallbackInitialized = true; - } + } this->Private->TimerCallbackInitialized = true; // This defines the interval at which the animation will proceed. 25Hz? this->Private->TimerId = interactor->CreateRepeatingTimer(1000 / 50); this->Private->AnimationIter = this->Private->AnimationPath.begin(); this->Private->AnimationPhase = 0; - } + } } void vtkScatterPlotMatrix::AdvanceAnimation() @@ -642,9 +642,9 @@ void vtkScatterPlotMatrix::AdvanceAnimation() // 6: Stop the timer. this->InvokeEvent(vtkCommand::AnimationCueTickEvent); switch (this->Private->AnimationPhase) - { + { case 0: // Remove decoration from the big chart, load up the 3D chart - { + { this->Private->NextActivePlot = *this->Private->AnimationIter; vtkChartXYZ *chart = this->Private->BigChart3D.GetPointer(); chart->SetVisible(false); @@ -662,37 +662,37 @@ void vtkScatterPlotMatrix::AdvanceAnimation() this->Private->IncAngle = this->Private->FinalAngle / this->NumberOfFrames; if (this->Private->NextActivePlot.GetY() == this->ActivePlot.GetY()) - { + { // Horizontal move. zColumn = this->Private->NextActivePlot.GetX(); isX = false; if (this->ActivePlot.GetX() < zColumn) - { + { this->Private->IncAngle *= 1.0; zSize = size.GetWidth(); - } + } else - { + { this->Private->IncAngle *= -1.0; zSize = -size.GetWidth(); - } } + } else - { + { // Vertical move. zColumn = this->GetSize().GetY() - this->Private->NextActivePlot.GetY() - 1; isX = true; if (this->GetSize().GetY() - this->ActivePlot.GetY() - 1 < zColumn) - { + { this->Private->IncAngle *= -1.0; zSize = size.GetHeight(); - } + } else - { + { this->Private->IncAngle *= 1.0; zSize = -size.GetHeight(); - } } + } chart->SetAroundX(isX); chart->SetGeometry(size); @@ -712,15 +712,15 @@ void vtkScatterPlotMatrix::AdvanceAnimation() chart->GetAxis(2)->SetPoint2(0, zSize); // Now set the ranges for the three axes. for (int i = 0; i < 3; ++i) - { + { PIMPL::ColumnSetting &settings = this->Private->ColumnSettings[names[i]]; chart->GetAxis(i)->SetUnscaledRange(settings.min, settings.max); - } + } chart->RecalculateTransform(); this->GetScene()->SetDirty(true); ++this->Private->AnimationPhase; return; - } + } case 1: // Make BigChart invisible, and BigChart3D visible. this->Private->BigChart->SetVisible(false); this->AddItem(this->Private->BigChart3D.GetPointer()); @@ -731,14 +731,14 @@ void vtkScatterPlotMatrix::AdvanceAnimation() return; case 2: // Rotation of the 3D chart from start to end angle. if (fabs(this->Private->CurrentAngle) < (this->Private->FinalAngle - 0.001)) - { + { this->Private->CurrentAngle += this->Private->IncAngle; this->Private->BigChart3D->SetAngle(this->Private->CurrentAngle); - } + } else - { + { ++this->Private->AnimationPhase; - } + } this->GetScene()->SetDirty(true); return; case 3: // Transition to new dimensionality, update the big chart. @@ -753,15 +753,15 @@ void vtkScatterPlotMatrix::AdvanceAnimation() // Clean up - we are done. this->Private->AnimationPhase = 0; if (this->Private->AnimationIter == this->Private->AnimationPath.end()) - { + { this->Private->BigChart->SetVisible(true); this->RemoveItem(this->Private->BigChart3D.GetPointer()); this->Private->BigChart3D->SetVisible(false); this->Private->Interactor->DestroyTimer(this->Private->TimerId); this->Private->TimerId = 0; this->Private->TimerCallbackInitialized = false; - } } + } } void vtkScatterPlotMatrix::ProcessEvents(vtkObject *, unsigned long event, @@ -770,22 +770,22 @@ void vtkScatterPlotMatrix::ProcessEvents(vtkObject *, unsigned long event, vtkScatterPlotMatrix *self = reinterpret_cast(clientData); switch (event) - { + { case vtkCommand::TimerEvent: - { + { // We must filter the events to ensure we actually get the timer event we // created. I would love signals and slots... int timerId = *reinterpret_cast(callerData); // Seems to work. if (self->Private->TimerCallbackInitialized && timerId == static_cast(self->Private->TimerId)) - { + { self->AdvanceAnimation(); - } - break; } - default: break; } + default: + break; + } } vtkAnnotationLink* vtkScatterPlotMatrix::GetAnnotationLink() @@ -796,13 +796,13 @@ vtkAnnotationLink* vtkScatterPlotMatrix::GetAnnotationLink() void vtkScatterPlotMatrix::SetInput(vtkTable *table) { if(table && table->GetNumberOfRows() == 0) - { + { // do nothing if the table is emtpy return; - } + } if (this->Input != table) - { + { // Set the input, then update the size of the scatter plot matrix, set // their inputs and all the other stuff needed. this->Input = table; @@ -810,55 +810,55 @@ void vtkScatterPlotMatrix::SetInput(vtkTable *table) this->Modified(); if (table == NULL) - { + { this->SetColumnVisibilityAll(true); return; - } + } int n = static_cast(this->Input->GetNumberOfColumns()); this->SetColumnVisibilityAll(true); this->SetSize(vtkVector2i(n, n)); - } + } } void vtkScatterPlotMatrix::SetColumnVisibility(const vtkStdString &name, bool visible) { if (visible) - { + { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Already there, nothing more needs to be done return; - } } + } // Add the column to the end of the list if it is a numeric column if (this->Input && this->Input->GetColumnByName(name.c_str()) && vtkArrayDownCast(this->Input->GetColumnByName(name.c_str()))) - { + { this->VisibleColumns->InsertNextValue(name); this->Private->VisibleColumnsModified = true; this->SetSize(vtkVector2i(0, 0)); this->SetSize(vtkVector2i(this->VisibleColumns->GetNumberOfTuples(), this->VisibleColumns->GetNumberOfTuples())); this->Modified(); - } } + } else - { + { // Remove the value if present for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { // Move all the later elements down by one, and reduce the size while (i < this->VisibleColumns->GetNumberOfTuples() - 1) - { + { this->VisibleColumns->SetValue(i, this->VisibleColumns->GetValue(i + 1)); ++i; - } + } this->VisibleColumns->SetNumberOfTuples( this->VisibleColumns->GetNumberOfTuples() - 1); this->SetSize(vtkVector2i(0, 0)); @@ -866,102 +866,102 @@ void vtkScatterPlotMatrix::SetColumnVisibility(const vtkStdString &name, this->VisibleColumns->GetNumberOfTuples())); if (this->ActivePlot.GetX() + this->ActivePlot.GetY() + 1 >= this->VisibleColumns->GetNumberOfTuples()) - { + { this->ActivePlot.Set(0, this->VisibleColumns->GetNumberOfTuples() - 1); - } + } this->Private->VisibleColumnsModified = true; this->Modified(); - } } } + } } void vtkScatterPlotMatrix::InsertVisibleColumn(const vtkStdString &name, int index) { if(!this->Input || !this->Input->GetColumnByName(name.c_str())) - { + { return; - } + } // Check if the column is already in the list. If yes, // we may need to rearrange the order of the columns. vtkIdType currIdx = -1; vtkIdType numCols = this->VisibleColumns->GetNumberOfTuples(); for (vtkIdType i = 0; i < numCols; ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { currIdx = i; break; - } } + } if(currIdx > 0 && currIdx == index) - { + { //This column is already there. return; - } + } if(currIdx < 0) - { + { this->VisibleColumns->SetNumberOfTuples(numCols+1); if(index >= numCols) - { + { this->VisibleColumns->SetValue(numCols, name); - } + } else // move all the values after index down 1 - { + { vtkIdType startidx = numCols; vtkIdType idx = (index < 0) ? 0 : index; while (startidx > idx) - { + { this->VisibleColumns->SetValue(startidx, this->VisibleColumns->GetValue(startidx-1)); startidx--; - } - this->VisibleColumns->SetValue(idx, name); } - this->Private->VisibleColumnsModified = true; + this->VisibleColumns->SetValue(idx, name); } + this->Private->VisibleColumnsModified = true; + } else // need to rearrange table columns - { + { vtkIdType toIdx = (index < 0) ? 0 : index; toIdx = toIdx>numCols ? numCols : toIdx; this->Private->VisibleColumnsModified = MoveColumn(this->VisibleColumns.GetPointer(), currIdx, toIdx); - } + } this->LayoutIsDirty = true; } bool vtkScatterPlotMatrix::GetColumnVisibility(const vtkStdString &name) { for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { if (this->VisibleColumns->GetValue(i) == name) - { + { return true; - } } + } return false; } void vtkScatterPlotMatrix::SetColumnVisibilityAll(bool visible) { if (visible && this->Input) - { + { vtkIdType n = this->Input->GetNumberOfColumns(); this->VisibleColumns->SetNumberOfTuples(n); for (vtkIdType i = 0; i < n; ++i) - { + { this->VisibleColumns->SetValue(i, this->Input->GetColumnName(i)); - } } + } else - { + { this->SetSize(vtkVector2i(0, 0)); this->VisibleColumns->SetNumberOfTuples(0); - } + } this->Private->VisibleColumnsModified = true; } @@ -974,16 +974,16 @@ vtkStringArray* vtkScatterPlotMatrix::GetVisibleColumns() void vtkScatterPlotMatrix::SetVisibleColumns(vtkStringArray* visColumns) { if(!visColumns || visColumns->GetNumberOfTuples() == 0) - { + { this->SetSize(vtkVector2i(0, 0)); this->VisibleColumns->SetNumberOfTuples(0); - } + } else - { + { this->VisibleColumns->SetNumberOfTuples( visColumns->GetNumberOfTuples()); this->VisibleColumns->DeepCopy(visColumns); - } + } this->Private->VisibleColumnsModified = true; this->LayoutIsDirty = true; } @@ -991,124 +991,124 @@ void vtkScatterPlotMatrix::SetVisibleColumns(vtkStringArray* visColumns) void vtkScatterPlotMatrix::SetNumberOfBins(int numberOfBins) { if (this->NumberOfBins != numberOfBins) - { + { this->NumberOfBins = numberOfBins; if (this->Input) - { + { PopulateHistograms(this->Input.GetPointer(), this->Private->Histogram.GetPointer(), this->VisibleColumns.GetPointer(), this->NumberOfBins); - } - this->Modified(); } + this->Modified(); + } } void vtkScatterPlotMatrix::SetPlotColor(int plotType, const vtkColor4ub& color) { if(plotType >= 0 && plotType < NOPLOT) - { + { if (plotType == ACTIVEPLOT || plotType == SCATTERPLOT) - { + { this->Private->ChartSettings[plotType]->PlotPen->SetColor(color); - } + } else - { + { this->Private->ChartSettings[HISTOGRAM]->PlotBrush->SetColor(color); - } - this->Modified(); } + this->Modified(); + } } void vtkScatterPlotMatrix::SetPlotMarkerStyle(int plotType, int style) { if(plotType >= 0 && plotType < NOPLOT && style != this->Private->ChartSettings[plotType]->MarkerStyle) - { + { this->Private->ChartSettings[plotType]->MarkerStyle = style; if (plotType == ACTIVEPLOT) - { + { vtkChart *chart = this->Private->BigChart; if (chart) - { + { vtkPlotPoints *plot = vtkPlotPoints::SafeDownCast(chart->GetPlot(0)); if (plot) - { + { plot->SetMarkerStyle(style); - } } - this->Modified(); } + this->Modified(); + } else if (plotType == SCATTERPLOT) - { + { int plotCount = this->GetSize().GetX(); for (int i = 0; i < plotCount - 1; ++i) - { + { for(int j = 0; j < plotCount - 1; ++j) - { + { if(this->GetPlotType(i, j) == SCATTERPLOT && this->GetChart(vtkVector2i(i, j))) - { + { vtkChart *chart = this->GetChart(vtkVector2i(i, j)); vtkPlotPoints *plot = vtkPlotPoints::SafeDownCast(chart->GetPlot(0)); if (plot) - { + { plot->SetMarkerStyle(style); - } } } } - this->Modified(); } + this->Modified(); } + } } void vtkScatterPlotMatrix::SetPlotMarkerSize(int plotType, float size) { if(plotType >= 0 && plotType < NOPLOT && size != this->Private->ChartSettings[plotType]->MarkerSize) - { + { this->Private->ChartSettings[plotType]->MarkerSize = size; if (plotType == ACTIVEPLOT) - { + { // update marker size on current active plot vtkChart *chart = this->Private->BigChart; if(chart) - { + { vtkPlotPoints *plot = vtkPlotPoints::SafeDownCast(chart->GetPlot(0)); if (plot) - { + { plot->SetMarkerSize(size); - } } - this->Modified(); } + this->Modified(); + } else if (plotType == SCATTERPLOT) - { + { int plotCount = this->GetSize().GetX(); for(int i = 0; i < plotCount - 1; i++) - { + { for(int j = 0; j < plotCount - 1; j++) - { + { if(this->GetPlotType(i, j) == SCATTERPLOT && this->GetChart(vtkVector2i(i, j))) - { + { vtkChart *chart = this->GetChart(vtkVector2i(i, j)); vtkPlotPoints *plot = vtkPlotPoints::SafeDownCast(chart ->GetPlot(0)); if (plot) - { + { plot->SetMarkerSize(size); - } } } } - this->Modified(); } + this->Modified(); } + } } bool vtkScatterPlotMatrix::Hit(const vtkContextMouseEvent &) @@ -1132,75 +1132,75 @@ bool vtkScatterPlotMatrix::MouseButtonReleaseEvent( { // Check we are not currently already animating if (this->Private->TimerCallbackInitialized) - { + { return true; - } + } // Work out which scatter plot was clicked - make that one the active plot. vtkVector2i pos = this->GetChartIndex(mouse.GetPos()); if(pos.GetX() == -1 || pos.GetX() + pos.GetY() + 1 >= this->Size.GetX()) - { + { // We didn't click a chart in the bottom-left triangle of the matrix. return true; - } + } // If the left button was used, hyperjump, if the right was used full path. if (mouse.GetButton() == vtkContextMouseEvent::LEFT_BUTTON) - { + { if (this->NumberOfFrames == 0) - { + { this->SetActivePlot(pos); return true; - } + } this->Private->AnimationPath.clear(); bool horizontalFirst = pos[0] > this->ActivePlot[0] ? false : true; if (horizontalFirst) - { + { if (pos[0] != this->ActivePlot[0]) - { + { this->Private->AnimationPath.push_back(vtkVector2i(pos[0], this->ActivePlot[1])); - } } + } else - { + { if (pos[1] != this->ActivePlot[1]) - { + { this->Private->AnimationPath.push_back(vtkVector2i(this->ActivePlot[0], pos[1])); - } } + } if ((this->Private->AnimationPath.size() == 1 && this->Private->AnimationPath.back() != pos) || (this->Private->AnimationPath.size() == 0 && this->ActivePlot != pos)) - { + { this->Private->AnimationPath.push_back(pos); - } + } if (this->Private->AnimationPath.size() > 0) - { + { this->InvokeEvent(vtkCommand::CreateTimerEvent); this->StartAnimation(mouse.GetInteractor()); - } } + } else if (mouse.GetButton() == vtkContextMouseEvent::RIGHT_BUTTON) - { + { if (this->NumberOfFrames == 0) - { + { this->SetActivePlot(pos); return true; - } + } this->UpdateAnimationPath(pos); if (this->Private->AnimationPath.size() > 0) - { + { this->InvokeEvent(vtkCommand::CreateTimerEvent); this->StartAnimation(mouse.GetInteractor()); - } + } else - { + { this->SetActivePlot(pos); - } } + } return true; } @@ -1234,32 +1234,32 @@ bool vtkScatterPlotMatrix::AddAnimationPath(const vtkVector2i &move) { vtkVector2i pos = this->ActivePlot; if (this->Private->AnimationPath.size()) - { + { pos = this->Private->AnimationPath.back(); - } + } if (move.GetX() != pos.GetX() && move.GetY() != pos.GetY()) - { + { // Can only move in x or y, not both. Do not append the element. return false; - } + } else - { + { this->Private->AnimationPath.push_back(move); return true; - } + } } bool vtkScatterPlotMatrix::BeginAnimationPath(vtkRenderWindowInteractor* interactor) { if (interactor && this->Private->AnimationPath.size()) - { + { this->StartAnimation(interactor); return true; - } + } else - { + { return false; - } + } } int vtkScatterPlotMatrix::GetPlotType(const vtkVector2i &pos) @@ -1267,22 +1267,22 @@ int vtkScatterPlotMatrix::GetPlotType(const vtkVector2i &pos) int plotCount = this->GetSize().GetX(); if(pos.GetX() + pos.GetY() + 1 < plotCount) - { + { return SCATTERPLOT; - } + } else if(pos.GetX() + pos.GetY() + 1 == plotCount) - { + { return HISTOGRAM; - } + } else if(pos.GetX() == pos.GetY() && pos.GetX() == static_cast(plotCount / 2.0) + plotCount % 2) - { + { return ACTIVEPLOT; - } + } else - { + { return NOPLOT; - } + } } int vtkScatterPlotMatrix::GetPlotType(int row, int column) @@ -1293,21 +1293,21 @@ int vtkScatterPlotMatrix::GetPlotType(int row, int column) void vtkScatterPlotMatrix::UpdateAxes() { if (!this->Input) - { + { return; - } + } // We need to iterate through all visible columns and set up the axis ranges. vtkAxis *axis(this->Private->TestAxis.GetPointer()); axis->SetPoint1(0, 0); axis->SetPoint2(0, 200); for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i) - { + { double range[2] = { 0, 0 }; std::string name(this->VisibleColumns->GetValue(i)); vtkDataArray *arr = vtkArrayDownCast(this->Input->GetColumnByName(name.c_str())); if (arr) - { + { PIMPL::ColumnSetting settings; arr->GetRange(range); // Apply a little padding either side of the ranges. @@ -1320,12 +1320,12 @@ void vtkScatterPlotMatrix::UpdateAxes() settings.nTicks = axis->GetNumberOfTicks(); settings.title = name; this->Private->ColumnSettings[name] = settings; - } + } else - { + { vtkDebugMacro(<< "No valid data array available. " << name); - } } + } } vtkStdString vtkScatterPlotMatrix::GetColumnName(int column) @@ -1380,14 +1380,14 @@ void vtkScatterPlotMatrix::UpdateLayout() this->UpdateAxes(); this->Private->BigChart3D->SetAnnotationLink(this->Private->Link.GetPointer()); for (int i = 0; i < n; ++i) - { + { vtkStdString column = this->GetColumnName(i); for (int j = 0; j < n; ++j) - { + { vtkStdString row = this->GetRowName(j); vtkVector2i pos(i, j); if (this->GetPlotType(pos) == SCATTERPLOT) - { + { vtkChart* chart = this->GetChart(pos); this->ApplyAxisSetting(chart, column, row); chart->ClearPlots(); @@ -1407,9 +1407,9 @@ void vtkScatterPlotMatrix::UpdateLayout() ->MarkerSize); plotPoints->SetMarkerStyle(this->Private->ChartSettings[SCATTERPLOT] ->MarkerStyle); - } + } else if (this->GetPlotType(pos) == HISTOGRAM) - { + { // We are on the diagonal - need a histogram plot. vtkChart* chart = this->GetChart(pos); chart->SetInteractive(false); @@ -1434,17 +1434,17 @@ void vtkScatterPlotMatrix::UpdateLayout() // Set the plot corner to the top-right vtkChartXY *xy = vtkChartXY::SafeDownCast(chart); if (xy) - { + { xy->SetBarWidthFraction(1.0); xy->SetPlotCorner(plot, 2); - } + } // set background color to light gray xy->SetBackgroundBrush(this->Private->ChartSettings[HISTOGRAM] ->BackgroundBrush.GetPointer()); - } + } else if (this->GetPlotType(pos) == ACTIVEPLOT) - { + { // This big plot in the top-right this->Private->BigChart = this->GetChart(pos); this->Private->BigChart->SetAnnotationLink( @@ -1457,9 +1457,9 @@ void vtkScatterPlotMatrix::UpdateLayout() vtkChartXY *chartXY = vtkChartXY::SafeDownCast(this->Private->BigChart.GetPointer()); if(chartXY) - { + { chartXY->SetTooltip(this->Private->TooltipItem); - } + } this->SetChartSpan(pos, vtkVector2i(n - i, n - j)); this->SetActivePlot(vtkVector2i(0, n - 2)); @@ -1467,10 +1467,10 @@ void vtkScatterPlotMatrix::UpdateLayout() // The big chart need to be resized only when it is // "between" the histograms, ie. when n is even. if (n%2 == 0) - { + { vtkVector2f resize(30, 30); if (this->CurrentPainter) - { + { // Try to use painter to resize the big plot vtkVector2i posLeft(i - 1, j); vtkVector2i posBottom(i, j - 1); @@ -1481,44 +1481,44 @@ void vtkScatterPlotMatrix::UpdateLayout() int resizeY = std::max(axis2->GetBoundingRect(this->CurrentPainter).GetWidth() - this->Gutter.GetY(), this->Gutter.GetY()); resize.Set(resizeX, resizeY); - } + } // Move big plot bottom left point to avoid overlap this->SetSpecificResize(pos, resize); - } } + } // Only show bottom axis label for bottom plots if (j > 0) - { + { vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::BOTTOM); axis->SetTitle(""); axis->SetLabelsVisible(false); axis->SetBehavior(vtkAxis::FIXED); - } + } else - { + { vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::BOTTOM); axis->SetTitle(this->VisibleColumns->GetValue(i)); axis->SetLabelsVisible(false); this->AttachAxisRangeListener(axis); - } + } // Only show the left axis labels for left-most plots if (i > 0) - { + { vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::LEFT); axis->SetTitle(""); axis->SetLabelsVisible(false); axis->SetBehavior(vtkAxis::FIXED); - } + } else - { + { vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::LEFT); axis->SetTitle(this->VisibleColumns->GetValue(n - j - 1)); axis->SetLabelsVisible(false); this->AttachAxisRangeListener(axis); - } } } + } } void vtkScatterPlotMatrix::AttachAxisRangeListener(vtkAxis* axis) @@ -1534,16 +1534,16 @@ void vtkScatterPlotMatrix::AxisRangeForwarderCallback(vtkObject*, double r[2]; int n = this->GetSize().GetX() - 1; for (int i = 0; i < n; ++i) - { + { this->GetChart(vtkVector2i(i, 0)) ->GetAxis(vtkAxis::BOTTOM) ->GetUnscaledRange(r); for (int j = 1; j < n - i; ++j) - { + { this->GetChart(vtkVector2i(i, j)) ->GetAxis(vtkAxis::BOTTOM) ->SetUnscaledRange(r); - } + } this->GetChart(vtkVector2i(i, n-i)) ->GetAxis(vtkAxis::TOP) ->SetUnscaledRange(r); @@ -1551,12 +1551,12 @@ void vtkScatterPlotMatrix::AxisRangeForwarderCallback(vtkObject*, ->GetAxis(vtkAxis::LEFT) ->GetUnscaledRange(r); for (int j = 1; j < n - i; ++j) - { + { this->GetChart(vtkVector2i(j, i)) ->GetAxis(vtkAxis::LEFT) ->SetUnscaledRange(r); - } } + } } void vtkScatterPlotMatrix::BigChartSelectionCallback(vtkObject*, @@ -1569,10 +1569,10 @@ void vtkScatterPlotMatrix::BigChartSelectionCallback(vtkObject*, void vtkScatterPlotMatrix::SetTitle(const vtkStdString& title) { if (this->Title != title) - { + { this->Title = title; this->Modified(); - } + } } vtkStdString vtkScatterPlotMatrix::GetTitle() @@ -1583,10 +1583,10 @@ vtkStdString vtkScatterPlotMatrix::GetTitle() void vtkScatterPlotMatrix::SetTitleProperties(vtkTextProperty *prop) { if (this->TitleProperties != prop) - { + { this->TitleProperties = prop; this->Modified(); - } + } } vtkTextProperty* vtkScatterPlotMatrix::GetTitleProperties() @@ -1599,18 +1599,18 @@ void vtkScatterPlotMatrix::SetAxisLabelProperties(int plotType, { if (plotType >= 0 && plotType < vtkScatterPlotMatrix::NOPLOT && this->Private->ChartSettings[plotType]->LabelFont != prop) - { + { this->Private->ChartSettings[plotType]->LabelFont = prop; this->Modified(); - } + } } vtkTextProperty* vtkScatterPlotMatrix::GetAxisLabelProperties(int plotType) { if (plotType >= 0 && plotType < vtkScatterPlotMatrix::NOPLOT) - { + { return this->Private->ChartSettings[plotType]->LabelFont.GetPointer(); - } + } return NULL; } @@ -1619,10 +1619,10 @@ void vtkScatterPlotMatrix::SetBackgroundColor(int plotType, const vtkColor4ub& color) { if (plotType >= 0 && plotType < vtkScatterPlotMatrix::NOPLOT) - { + { this->Private->ChartSettings[plotType]->BackgroundBrush->SetColor(color); this->Modified(); - } + } } //---------------------------------------------------------------------------- @@ -1630,21 +1630,21 @@ void vtkScatterPlotMatrix::SetAxisColor(int plotType, const vtkColor4ub& color) { if (plotType >= 0 && plotType < vtkScatterPlotMatrix::NOPLOT) - { + { this->Private->ChartSettings[plotType]->AxisColor = color; this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetGridVisibility(int plotType, bool visible) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->ShowGrid = visible; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- @@ -1652,66 +1652,66 @@ void vtkScatterPlotMatrix::SetGridColor(int plotType, const vtkColor4ub& color) { if (plotType >= 0 && plotType < vtkScatterPlotMatrix::NOPLOT) - { + { this->Private->ChartSettings[plotType]->GridColor = color; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetAxisLabelVisibility(int plotType, bool visible) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->ShowAxisLabels = visible; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetAxisLabelNotation(int plotType, int notation) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->LabelNotation = notation; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetAxisLabelPrecision(int plotType, int precision) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->LabelPrecision = precision; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetTooltipNotation(int plotType, int notation) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->TooltipNotation = notation; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetTooltipPrecision(int plotType, int precision) { if(plotType!= NOPLOT) - { + { this->Private->ChartSettings[plotType]->TooltipPrecision = precision; // How to update this->Modified(); - } + } } //---------------------------------------------------------------------------- @@ -1734,29 +1734,29 @@ void vtkScatterPlotMatrix::SetScatterPlotSelectedActiveColor( void vtkScatterPlotMatrix::UpdateChartSettings(int plotType) { if (plotType == HISTOGRAM) - { + { int plotCount = this->GetSize().GetX(); for(int i = 0; i < plotCount; i++) - { + { vtkChart *chart = this->GetChart(vtkVector2i(i, plotCount - i - 1)); this->Private->UpdateAxis(chart->GetAxis(vtkAxis::TOP), this->Private->ChartSettings[HISTOGRAM]); this->Private->UpdateAxis(chart->GetAxis(vtkAxis::RIGHT), this->Private->ChartSettings[HISTOGRAM]); this->Private->UpdateChart(chart, this->Private->ChartSettings[HISTOGRAM]); - } } + } else if (plotType == SCATTERPLOT) - { + { int plotCount = this->GetSize().GetX(); for (int i = 0; i < plotCount - 1; i++) - { + { for (int j = 0; j < plotCount - 1; j++) - { + { if (this->GetPlotType(i, j) == SCATTERPLOT) - { + { vtkChart *chart = this->GetChart(vtkVector2i(i, j)); bool updateleft = i==0 ? true : false; bool updatebottom = j==0 ? true : false; @@ -1764,12 +1764,12 @@ void vtkScatterPlotMatrix::UpdateChartSettings(int plotType) this->Private->ChartSettings[SCATTERPLOT], updateleft); this->Private->UpdateAxis(chart->GetAxis(vtkAxis::BOTTOM), this->Private->ChartSettings[SCATTERPLOT], updatebottom); - } } } } + } else if (plotType == ACTIVEPLOT && this->Private->BigChart) - { + { this->Private->UpdateAxis(this->Private->BigChart->GetAxis(vtkAxis::TOP), this->Private->ChartSettings[ACTIVEPLOT]); this->Private->UpdateAxis(this->Private->BigChart->GetAxis(vtkAxis::RIGHT), @@ -1777,23 +1777,23 @@ void vtkScatterPlotMatrix::UpdateChartSettings(int plotType) this->Private->UpdateChart(this->Private->BigChart, this->Private->ChartSettings[ACTIVEPLOT]); this->Private->BigChart->SetSelectionMode(this->SelectionMode); - } + } this->Modified(); } //----------------------------------------------------------------------------- void vtkScatterPlotMatrix::SetSelectionMode(int selMode) - { +{ if (this->SelectionMode == selMode || selMode < vtkContextScene::SELECTION_NONE || selMode > vtkContextScene::SELECTION_TOGGLE) - { + { return; - } + } this->SelectionMode = selMode; if(this->Private->BigChart) - { + { this->Private->BigChart->SetSelectionMode(selMode); - } + } this->Modified(); } @@ -1876,7 +1876,7 @@ int vtkScatterPlotMatrix::GetTooltipPrecision(int plotType) void vtkScatterPlotMatrix::SetTooltip(vtkTooltipItem *tooltip) { if(tooltip != this->Private->TooltipItem) - { + { this->Private->TooltipItem = tooltip; this->Modified(); @@ -1884,10 +1884,10 @@ void vtkScatterPlotMatrix::SetTooltip(vtkTooltipItem *tooltip) vtkChartXY::SafeDownCast(this->Private->BigChart.GetPointer()); if(chartXY) - { + { chartXY->SetTooltip(tooltip); - } } + } } //---------------------------------------------------------------------------- @@ -1900,20 +1900,20 @@ vtkTooltipItem* vtkScatterPlotMatrix::GetTooltip() const void vtkScatterPlotMatrix::SetIndexedLabels(vtkStringArray *labels) { if(labels != this->Private->IndexedLabelsArray) - { + { this->Private->IndexedLabelsArray = labels; this->Modified(); if(this->Private->BigChart) - { + { vtkPlot *plot = this->Private->BigChart->GetPlot(0); if(plot) - { + { plot->SetIndexedLabels(labels); - } } } + } } //---------------------------------------------------------------------------- diff --git a/Common/Color/Testing/Cxx/TestCategoricalColors.cxx b/Common/Color/Testing/Cxx/TestCategoricalColors.cxx index 9240596086a..37e03b509f1 100644 --- a/Common/Color/Testing/Cxx/TestCategoricalColors.cxx +++ b/Common/Color/Testing/Cxx/TestCategoricalColors.cxx @@ -62,10 +62,10 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) #if 0 vtkIdType numSchemes = palettes->GetNumberOfColorSchemes(); for (vtkIdType i = 0; i < numSchemes; ++ i) - { + { palettes->SetColorScheme(i); std::cout << i << ": " << palettes->GetColorSchemeName() << std::endl; - } + } #endif palettes->SetColorSchemeByName("Brewer Qualitative Accent"); palettes->BuildLookupTable(lut); @@ -82,7 +82,7 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) const unsigned char* rgba = lut->MapValue(0.); std::string v = "0x" + RGBAToHexString(rgba); if (expectedColors[0] != v) - { + { std::cout << "Fail for " << std::setw(3) << std::left @@ -92,11 +92,11 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << expectedColors[0] << std::endl; res &= false; - } + } rgba = lut->MapValue(3.); v = "0x" + RGBAToHexString(rgba); if (expectedColors[3] != v) - { + { std::cout << "Fail for " << std::setw(3) << std::left @@ -106,7 +106,7 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << expectedColors[3] << std::endl; res &= false; - } + } vtkDoubleArray* data = vtkDoubleArray::New(); data->InsertNextValue(0.); @@ -120,11 +120,11 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) vtkUnsignedCharArray* color = lut->MapScalars(data, VTK_RGBA, 0); unsigned char* cval; for (vtkIdType i = 0; i < color->GetNumberOfTuples(); ++ i) - { + { cval = color->GetPointer(i * 4); v = "0x" + RGBAToHexString(cval); if (expectedColors[data->GetTuple1(i)] != v) - { + { std::cout << "Fail for " << std::setw(3) << std::left @@ -134,12 +134,12 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << expectedColors[data->GetTuple1(i)] << std::endl; res &= false; - } } + } cval = lut->GetNanColorAsUnsignedChars(); v = "0x" + RGBAToHexString(cval); if (expectedColors[-999] != v) - { + { std::cout << "Fail for " << "NaN: got: " @@ -148,7 +148,7 @@ int TestCategoricalColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << expectedColors[-999] << std::endl; res &= false; - } + } color->Delete(); data->Delete(); diff --git a/Common/Color/Testing/Cxx/TestColorSeries.cxx b/Common/Color/Testing/Cxx/TestColorSeries.cxx index 49804aefd42..ae45dbe1cea 100644 --- a/Common/Color/Testing/Cxx/TestColorSeries.cxx +++ b/Common/Color/Testing/Cxx/TestColorSeries.cxx @@ -37,9 +37,9 @@ int TestColorSeries( int argc, char* argv[] ) int valResult = vtkTesting::PASSED; vtkTesting* t = vtkTesting::New(); for ( int cc = 1; cc < argc; ++ cc ) - { + { t->AddArgument(argv[cc]); - } + } VTK_CREATE(vtkColorSeries,palettes); vtkColor3ub color; @@ -51,17 +51,17 @@ int TestColorSeries( int argc, char* argv[] ) // Should return black as there are no colors: color = palettes->GetColor( 0 ); if ( ! black.Compare( color, 1 ) ) - { + { vtkGenericWarningMacro( "Failure: GetColor on empty palette" ); valResult = vtkTesting::FAILED; - } + } // Should return black as there are no colors: color = palettes->GetColorRepeating( 0 ); if ( ! black.Compare( color, 1 ) ) - { + { vtkGenericWarningMacro( "Failure: GetColorRepeating on empty palette" ); valResult = vtkTesting::FAILED; - } + } // Test appending colors: color = vtkColor3ub( 255, 255, 255 ); palettes->AddColor( color ); @@ -83,12 +83,12 @@ int TestColorSeries( int argc, char* argv[] ) // First, find the largest number of colors in any palette: int mps = 0; // maximum palette size for ( int p = 0; p < np; ++ p ) - { + { palettes->SetColorScheme( p ); int nc = palettes->GetNumberOfColors(); // in the current scheme if ( nc > mps ) mps = nc; - } + } // Now size the test image properly and generate swatches pix->SetNumberOfTuples( np * 5 * mps * 5 ); pix->FillComponent( 0, 255 ); @@ -97,7 +97,7 @@ int TestColorSeries( int argc, char* argv[] ) img->SetExtent( 0, mps * 5 - 1, 0, np * 5 - 1, 0, 0 ); img->GetPointData()->SetScalars( pix.GetPointer() ); for ( int p = 0; p < np; ++ p ) - { + { palettes->SetColorScheme( p ); int nc = palettes->GetNumberOfColors(); // in the current scheme /* @@ -107,12 +107,12 @@ int TestColorSeries( int argc, char* argv[] ) */ int yoff = ( np - p - 1 ) * 5; // Put palette 0 at the top of the image for ( int c = 0; c < nc; ++ c ) - { + { color = palettes->GetColorRepeating( c ); for ( int i = 1; i < 4; ++ i ) - { + { for ( int j = 1; j < 4; ++ j ) - { + { vtkIdType coord = ( ( ( yoff + i ) * mps + c ) * 5 + j ) * 3; /* cout @@ -122,10 +122,10 @@ int TestColorSeries( int argc, char* argv[] ) pix->SetValue( coord ++, color.GetRed() ); pix->SetValue( coord ++, color.GetGreen() ); pix->SetValue( coord ++, color.GetBlue() ); - } } } } + } /* Uncomment to save an updated test image. VTK_CREATE(vtkPNGWriter,wri); @@ -142,64 +142,64 @@ int TestColorSeries( int argc, char* argv[] ) vtkStdString palName = palettes->GetColorSchemeName(); vtkStdString expected( "Brewer Sequential Blue-Green (9) copy" ); if ( palName != expected ) - { + { vtkGenericWarningMacro( << "Failure: Palette copy-on-write: name should have been " << "\"" << expected.c_str() << "\" but was " << "\"" << palName.c_str() << "\" instead." ); valResult = vtkTesting::FAILED; - } + } if ( palettes->GetNumberOfColors() != 10 ) - { + { vtkGenericWarningMacro( << "Modified palette should have had 10 entries but had " << palettes->GetNumberOfColors() << " instead." ); valResult = vtkTesting::FAILED; - } + } palettes->SetColorSchemeName(""); // Test bad name... should have no effect. palName = palettes->GetColorSchemeName(); if ( palName != expected ) - { + { vtkGenericWarningMacro( << "Failure: Setting empty palette name should have no effect." ); valResult = vtkTesting::FAILED; - } + } // Check setting a custom palette name and non-copy-on-write // behavior for custom palettes: palettes->SetColorSchemeName("Unoriginal Blue-Green"); palettes->SetColorSchemeByName("Unoriginal Blue-Green"); if ( np != palettes->GetColorScheme() ) - { + { vtkGenericWarningMacro( << "Modified palette had ID " << palettes->GetColorScheme() << " not expected ID " << np ); valResult = vtkTesting::FAILED; - } + } palettes->SetNumberOfColors( 8 ); if ( palettes->GetNumberOfColors() != 8 ) - { + { vtkGenericWarningMacro( << "Resized palette should have had 8 entries but had " << palettes->GetNumberOfColors() << " instead." ); valResult = vtkTesting::FAILED; - } + } palettes->ClearColors(); if ( palettes->GetNumberOfColors() != 0 ) - { + { vtkGenericWarningMacro( << "Cleared palette should have had 0 entries but had " << palettes->GetNumberOfColors() << " instead." ); valResult = vtkTesting::FAILED; - } + } // Make sure our custom scheme is still around @@ -208,19 +208,19 @@ int TestColorSeries( int argc, char* argv[] ) color = palettes->GetColor( 2 ); // Should return blue vtkColor3ub blue( 0, 0, 255 ); if ( ! blue.Compare( color, 1 ) ) - { + { vtkGenericWarningMacro( "Failure: GetColor on small test palette" ); valResult = vtkTesting::FAILED; - } + } // Test DeepCopy VTK_CREATE(vtkColorSeries,other); other->DeepCopy(palettes); if ( other->GetColorScheme() != palettes->GetColorScheme() ) - { + { vtkGenericWarningMacro( "Failure: DeepCopy did not preserve current scheme" ); valResult = vtkTesting::FAILED; - } + } other->DeepCopy(NULL); // Test SetColor @@ -228,10 +228,10 @@ int TestColorSeries( int argc, char* argv[] ) other->SetColor( 0, blue ); color = other->GetColor( 0 ); if ( ! blue.Compare( color, 1 ) ) - { + { vtkGenericWarningMacro( "Failure: SetColor on test palette" ); valResult = vtkTesting::FAILED; - } + } // Build a lookup table vtkLookupTable* lut = palettes->CreateLookupTable(); @@ -243,15 +243,15 @@ int TestColorSeries( int argc, char* argv[] ) palettes->AddObserver(vtkCommand::WarningEvent, warningObserver); palettes->SetColorScheme(1000); if (warningObserver->GetWarning()) - { + { std::cout << "Caught expected warning: " << warningObserver->GetWarningMessage() << std::endl; - } + } else - { + { vtkGenericWarningMacro( "Failure: SetColorScheme(1000) did not produce expected warning" ); valResult = vtkTesting::FAILED; - } + } vtkIndent indent; palettes->PrintSelf(std::cout, indent); diff --git a/Common/Color/Testing/Cxx/TestColorSeriesLookupTables.cxx b/Common/Color/Testing/Cxx/TestColorSeriesLookupTables.cxx index 6a5961e9fdb..cd228a6fc5e 100644 --- a/Common/Color/Testing/Cxx/TestColorSeriesLookupTables.cxx +++ b/Common/Color/Testing/Cxx/TestColorSeriesLookupTables.cxx @@ -34,20 +34,20 @@ std::string RGBAToDoubleString(double *rgba) std::ostringstream os; os << "["; for (int i = 0; i < 4; ++i) - { + { if (i == 0) - { + { os << std::fixed << std::setw(8) << std::setprecision(6) << rgba[i]; - } + } else - { + { os << std::fixed << std::setw(9) << std::setprecision(6) << rgba[i]; - } + } if (i < 3) - { + { os << ","; - } } + } os << "]"; return os.str(); } @@ -59,20 +59,20 @@ std::string RGBAToCharString(double *rgba) std::ostringstream os; os << "["; for (int i = 0; i < 4; ++i) - { + { if (i == 0) - { + { os << std::setw(3) << static_cast(rgba[i] * 255); - } + } else - { + { os << std::setw(4) << static_cast(rgba[i] * 255); - } + } if (i < 3) - { + { os << ","; - } } + } os << "]"; return os.str(); } @@ -117,12 +117,12 @@ std::string DisplayOrdinalLUTAsString(vtkLookupTable *lut) << dR[0] << " to " << dR[1] << std::endl; std::vector indices; for (int i = 0; i < tv; ++i) - { + { indices.push_back((dR[1] - dR[0]) * i / tv + dR[0]); - } + } for (std::vector::const_iterator p = indices.begin(); p != indices.end(); ++p) - { + { double rgba[4]; lut->GetColor(*p, rgba); rgba[3] = lut->GetOpacity(*p); @@ -133,7 +133,7 @@ std::string DisplayOrdinalLUTAsString(vtkLookupTable *lut) os << RGBToHexString(rgba); os << " "; os << std::endl; - } + } return os.str(); } @@ -149,7 +149,7 @@ std::string DisplayCategoricalLUTAsString(vtkLookupTable *lut) << " Table Range: " << std::fixed << std::setw(8) << std::setprecision(6) << dR[0] << " to " << dR[1] << std::endl; for (vtkIdType i = 0; i < tv; ++i) - { + { const unsigned char* cval = lut->MapValue(i); double rgba[4]; for (int j = 0; j < 4; ++j) @@ -163,7 +163,7 @@ std::string DisplayCategoricalLUTAsString(vtkLookupTable *lut) os << RGBToHexString(rgba); os << " "; os << std::endl; - } + } return os.str(); } @@ -174,34 +174,34 @@ std::pair CompareOrdinalLUTs(vtkLookupTable *lut1, { std::pair res(true, ""); if (lut1->GetNumberOfTableValues() != lut2->GetNumberOfTableValues()) - { + { res.first = false; res.second = "Table values do not match."; - } + } else - { + { double dR1[2]; lut1->GetTableRange(dR1); double dR2[2]; lut2->GetTableRange(dR2); if (dR1[0] != dR2[0] && dR2[1] != dR1[1]) - { + { res.first = false; res.second = "Table ranges do not match."; - } + } else - { + { vtkIdType tv = lut1->GetNumberOfTableValues(); double dR[2]; lut1->GetTableRange(dR); std::vector indices; for (int i = 0; i < tv; ++i) - { + { indices.push_back((dR[1] - dR[0]) * i / tv + dR[0]); - } + } for (std::vector::const_iterator p = indices.begin(); p != indices.end(); ++p) - { + { double rgba1[4]; lut1->GetColor(*p, rgba1); rgba1[3] = lut1->GetOpacity(*p); @@ -210,22 +210,22 @@ std::pair CompareOrdinalLUTs(vtkLookupTable *lut1, rgba2[3] = lut2->GetOpacity(*p); bool areEquivalent = true; for (int i = 0; i < 4; ++i) - { + { areEquivalent &= rgba1[i] == rgba2[i]; if (!areEquivalent) - { + { break; - } } + } if (!areEquivalent) - { + { res.first = false; res.second = "Colors do not match."; break; - } } } } + } return res; } @@ -236,38 +236,38 @@ std::pair CompareCategoricalLUTs(vtkLookupTable *lut1, { std::pair res(true, ""); if (lut1->GetNumberOfTableValues() != lut2->GetNumberOfTableValues()) - { + { res.first = false; res.second = "Table values do not match."; - } + } else - { + { double dR1[2]; lut1->GetTableRange(dR1); double dR2[2]; lut2->GetTableRange(dR2); if (dR1[0] != dR2[0] && dR2[1] != dR1[1]) - { + { res.first = false; res.second = "Table ranges do not match."; - } + } else - { + { vtkIdType tv = lut1->GetNumberOfTableValues(); double dR[2]; lut1->GetTableRange(dR); std::vector indices; for (int i = 0; i < tv; ++i) - { + { indices.push_back((dR[1] - dR[0]) * i / tv + dR[0]); - } + } vtkSmartPointer data = vtkSmartPointer::New(); for (std::vector::const_iterator p = indices.begin(); p != indices.end(); ++p) - { + { data->InsertNextValue(*p); - } + } vtkUnsignedCharArray *color1 = lut1->MapScalars(data, VTK_RGBA, 0); vtkUnsignedCharArray *color2 = @@ -275,29 +275,29 @@ std::pair CompareCategoricalLUTs(vtkLookupTable *lut1, unsigned char* cval1; unsigned char* cval2; for (vtkIdType i = 0; i < color1->GetNumberOfTuples(); ++i) - { + { cval1 = color1->GetPointer(i * 4); cval2 = color2->GetPointer(i * 4); bool areEquivalent = true; for (int j = 0; j < 4; ++j) - { + { areEquivalent &= cval1[j] == cval2[j]; if (!areEquivalent) - { + { break; - } } + } if (!areEquivalent) - { + { res.first = false; res.second = "Colors do not match."; break; - } } + } color1->Delete(); color2->Delete(); } - } + } return res; } @@ -320,14 +320,14 @@ int TestColorSeriesLookupTables(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) vtkSmartPointer ::New(); std::string str = "abcdefghijklmnopqrstuvwxyz"; for (size_t i = 0; i < 10; ++i) - { + { values->InsertNextValue(vtkVariant(str.substr(i, 1))); - } + } for (int i = 0; i < values->GetNumberOfTuples(); ++i) - { + { lut3->SetAnnotation(i, values->GetValue(i).ToString()); lut4->SetAnnotation(i, values->GetValue(i).ToString()); - } + } colorSeries->BuildLookupTable(lut1); // Convert from categorical to ordinal. @@ -336,7 +336,7 @@ int TestColorSeriesLookupTables(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) // lut1 & lut2 should be ordinal lookup tables. std::pair comparison = CompareOrdinalLUTs(lut1, lut2); if (!comparison.first) - { + { std::cout << line; std::cout << std::boolalpha << comparison.first << " " << std::noboolalpha << comparison.second << std::endl; @@ -346,14 +346,14 @@ int TestColorSeriesLookupTables(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) std::cout << DisplayOrdinalLUTAsString(lut2) << std::endl; std::cout << line; res &= comparison.first; - } + } // lut3 will be categorical. colorSeries->BuildLookupTable(lut3, 99); // Expecting a fail here as the tables are different. // lut2 is ordinal and lut3 is categorical. comparison = CompareOrdinalLUTs(lut2, lut3); if (comparison.first) - { + { std::cout << line; std::cout << std::boolalpha << comparison.first << " " << std::noboolalpha << comparison.second << std::endl; @@ -363,16 +363,16 @@ int TestColorSeriesLookupTables(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) std::cout << DisplayCategoricalLUTAsString(lut3) << std::endl; std::cout << line; res &= !comparison.first; - } + } else - { + { res &= !comparison.first; - } + } // lut3 and lut4 will be categorical. colorSeries->BuildLookupTable(lut4); comparison = CompareCategoricalLUTs(lut3, lut4); if (!comparison.first) - { + { std::cout << line; std::cout << std::boolalpha << comparison.first << " " << std::noboolalpha << comparison.second << std::endl; @@ -382,7 +382,7 @@ int TestColorSeriesLookupTables(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) std::cout << DisplayCategoricalLUTAsString(lut4) << std::endl; std::cout << line; res &= comparison.first; - } + } return (res) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/Common/Color/Testing/Cxx/TestNamedColors.cxx b/Common/Color/Testing/Cxx/TestNamedColors.cxx index bd495e115f1..7e80b4738be 100644 --- a/Common/Color/Testing/Cxx/TestNamedColors.cxx +++ b/Common/Color/Testing/Cxx/TestNamedColors.cxx @@ -94,34 +94,34 @@ bool TestEmptyColorName() unsigned char ra = 255; vtkColor4ub v = nc->GetColor4ub(name); if ( v[0] != rr || v[1] != rg || v[2] != rb || v[3] != ra ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned an unsigned char color other than black." ); return false; - } + } vtkColor3ub v3 = nc->GetColor3ub(name); if ( v3[0] != rr || v3[1] != rg || v3[2] != rb ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned an unsigned char color other than black." ); return false; - } + } unsigned char ur, ug, ub; ur = ug = ub = 0; unsigned char ua = 0; nc->GetColor(name,ur,ug,ub,ua); if ( ur != rr || ug != rg || ub != rb || ua != ra ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned an unsigned char color other than black." ); return false; - } + } // Reference color double rrd, rgd, rbd; @@ -129,43 +129,43 @@ bool TestEmptyColorName() double rad = 1; vtkColor4d vd = nc->GetColor4d(name); if ( vd[0] != rrd || vd[1] != rgd || vd[2] != rbd || vd[3] != rad ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned a double color other than black." ); return false; - } + } vtkColor3d vd3 = nc->GetColor3d(name); if ( vd3[0] != rrd || vd3[1] != rgd || vd3[2] != rbd ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned a double color other than black." ); return false; - } + } double dr, dg, db; dr = dg = db = 1; double da = 0; nc->GetColor(name,dr,dg,db,da); if ( dr != rrd || dg != rgd || db != rbd || da != rad ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned an double color other than black." ); return false; - } + } nc->GetColor(name,dr,dg,db); if ( ur != rrd || dg != rgd || db != rbd ) - { + { vtkGenericWarningMacro( << "Fail: an empty color name " << "returned an double color other than black." ); return false; - } + } return true; } @@ -174,13 +174,13 @@ bool TestNoSuchColor(vtkStdString const & name) { vtkSmartPointer nc = vtkSmartPointer::New(); if ( nc->ColorExists(name) ) - { + { vtkGenericWarningMacro( << "Fail: the color " << name << " exists when it shouldn't." ); return false; - } + } return true; } @@ -193,69 +193,69 @@ bool TestUnsignedChar(vtkStdString const & name) nc->GetColor(name,cv); bool sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( v[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } sameElements = true; nc->GetColor(name,v); for ( int i = 0; i < 4; ++i ) - { + { if ( v[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } sameElements = true; vtkColor3ub vv; nc->GetColor(name,vv); for ( int i = 0; i < 3; ++i ) - { + { if ( vv[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); return false; - } + } unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; nc->GetColor(name, red, green, blue, alpha); if ( red != v[0] && blue != v[1] && green != v[2] && alpha != v[3] ) - { + { vtkGenericWarningMacro( << "Fail: One of red, green blue or alpha do not match the array " << "for color: " << name ); return false; - } + } return true; } @@ -268,69 +268,69 @@ bool TestDouble(vtkStdString const & name) nc->GetColor(name,cv); bool sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( v[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } sameElements = true; nc->GetColor(name,v); for ( int i = 0; i < 4; ++i ) - { + { if ( v[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } sameElements = true; vtkColor3d vv; nc->GetColor(name,vv); for ( int i = 0; i < 3; ++i ) - { + { if ( vv[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); return false; - } + } double red; double green; double blue; double alpha; nc->GetColor(name, red, green, blue, alpha); if ( red != v[0] && blue != v[1] && green != v[2] && alpha != v[3] ) - { + { vtkGenericWarningMacro( << "Fail: One of red, green blue or alpha do not match the array " << "for color: " << name ); return false; - } + } return true; } @@ -343,32 +343,32 @@ bool TestDoubleRGB(vtkStdString const & name) nc->GetColorRGB(name,cv); bool sameElements = true; for ( int i = 0; i < 3; ++i ) - { + { if ( v[i] != cv[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } double red; double green; double blue; nc->GetColor(name, red, green, blue); if ( red != v[0] && blue != v[1] && green != v[2] ) - { + { vtkGenericWarningMacro( << "Fail: One of red, green or blue do not match the array " << "for color: " << name ); return false; - } + } return true; } @@ -380,25 +380,25 @@ bool TestUCharToDouble(vtkStdString const & name) vtkColor4d vd = nc->GetColor4d(name); double vdu[4]; for ( int i = 0; i < 4; ++i ) - { + { vdu[i] = static_cast(vu[i]) / 255.0; - } + } bool sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( std::abs(vd[i] - vdu[i]) > EPS2 ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: arrays are not the same " << "for color: " << name ); - } + } return sameElements; } @@ -414,80 +414,80 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], vtkColor3ub ub3; vtkColor3d d3; for(int i = 0; i < 3; ++i) - { + { ub3[i] = ub4[i]; d3[i] = d4[i]; - } + } // Test for adding empty names. nc->SetColor("",dcolor); nc->SetColor("",dcolor[0],dcolor[1],dcolor[2],dcolor[3]); if(sz != nc->GetNumberOfColors()) - { + { vtkGenericWarningMacro( << "Fail: Setting a double color with an empty name." ); nc->ResetColors(); return false; - } + } nc->SetColor("",ucolor); nc->SetColor("",ucolor[0],ucolor[1],ucolor[2],ucolor[3]); if(sz != nc->GetNumberOfColors()) - { + { vtkGenericWarningMacro( << "Fail: Setting an unsigned char color with an empty name." ); nc->ResetColors(); return false; - } + } nc->SetColor(name,dcolor); vtkColor4ub vu = nc->GetColor4ub(name); bool sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( vu[i] != ucolor[i] ) - { + { sameElements &= false; break; - } } + } if (!sameElements) - { + { vtkGenericWarningMacro( << "Fail: Set as double get as unsigned char, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } nc->SetColor(name,ucolor); vtkColor4d vd = nc->GetColor4d(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( std::abs(vd[i] - dcolor[i]) > EPS1 ) - { + { sameElements &= false; - } } + } if ( !sameElements ) - { + { vtkGenericWarningMacro( << "Fail: Set as unsigned char get as double, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } // Set/Get as unsigned char. unsigned char uc[4]; for( size_t i = 0; i < 4; ++i ) - { + { uc[i] = ucolor[i]; - } + } unsigned char ur, ug, ub, ua; ur = ucolor[0]; ug = ucolor[1]; @@ -497,14 +497,14 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], vu = nc->GetColor4ub(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( vu[i] != uc[i] ) - { + { sameElements &= false; - } } + } if ( !sameElements ) - { + { vtkGenericWarningMacro( << "Fail: Set as unsigned char array get as vtkColor4ub, " << "colors do not match " @@ -512,20 +512,20 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], ); nc->ResetColors(); return false; - } + } nc->SetColor(name,ub4); vu = nc->GetColor4ub(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( vu[i] != uc[i] ) - { + { sameElements &= false; - } } + } if ( !sameElements ) - { + { vtkGenericWarningMacro( << "Fail: Set as vtkColor4ub array get as vtkColor4ub, " << "colors do not match " @@ -533,20 +533,20 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], ); nc->ResetColors(); return false; - } + } nc->SetColor(name,ub3); vu = nc->GetColor4ub(name); sameElements = true; for ( int i = 0; i < 3; ++i ) - { + { if ( vu[i] != uc[i] ) - { + { sameElements &= false; - } } + } if ( !sameElements ) - { + { vtkGenericWarningMacro( << "Fail: Set as vtkColor3ub array get as vtkColor4ub, " << "colors do not match " @@ -554,20 +554,20 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], ); nc->ResetColors(); return false; - } + } nc->SetColor(name,ur,ug,ub,ua); vu = nc->GetColor4ub(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( vu[i] != uc[i] ) - { + { sameElements &= false; - } } + } if ( !sameElements ) - { + { vtkGenericWarningMacro( << "Fail: Set as unsigned char values get as vtkColor4ub, " << "colors do not match " @@ -575,14 +575,14 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], ); nc->ResetColors(); return false; - } + } // Set/Get as double. double d[4]; for( size_t i = 0; i < 4; ++i ) - { + { d[i] = dcolor[i]; - } + } double dr, dg, db, da; dr = dcolor[0]; dg = dcolor[1]; @@ -592,90 +592,90 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], vd = nc->GetColor4d(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( std::abs(vd[i] - d[i]) > EPS2 ) - { + { sameElements &= false; break; - } } + } if(!sameElements) - { + { vtkGenericWarningMacro( << "Fail: Set as double array get as vtkColor4d, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } nc->SetColor(name,d4); vd = nc->GetColor4d(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( std::abs(vd[i] - d[i]) > EPS2 ) - { + { sameElements &= false; break; - } } + } if(!sameElements) - { + { vtkGenericWarningMacro( << "Fail: Set as vtkColor4d get as vtkColor4d, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } nc->SetColor(name,dr,dg,db,da); vd = nc->GetColor4d(name); sameElements = true; for ( int i = 0; i < 4; ++i ) - { + { if ( std::abs(vd[i] - d[i]) > EPS2 ) - { + { sameElements &= false; break; - } } + } if(!sameElements) - { + { vtkGenericWarningMacro( << "Fail: Set as double values get as vtkColor4d, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } nc->SetColor(name,d3); vd = nc->GetColor4d(name); sameElements = true; for ( int i = 0; i < 3; ++i ) - { + { if ( std::abs(vd[i] - d[i]) > EPS2 ) - { + { sameElements &= false; break; - } } + } if(!sameElements) - { + { vtkGenericWarningMacro( << "Fail: Set as vtkColor3d get as vtkColor4d, colors do not match " << "for color: " << name ); nc->ResetColors(); return false; - } + } nc->RemoveColor(name); sz = nc->GetNumberOfColors(); if (sz != NUMBER_OF_COLORS) - { + { vtkGenericWarningMacro( << "Fail: Incorrect number of colors found, expected " << nc->GetNumberOfColors() << ", got " @@ -684,7 +684,7 @@ bool TestAddingAColor(vtkStdString name, const double dcolor[4], ); nc->ResetColors(); return false; - } + } return true; } @@ -698,16 +698,16 @@ std::vector ParseColorNames(const vtkStdString & colorNames) size_t start = 0; size_t end = colorNames.find(colorDelimiter); while(end != std::string::npos) - { + { cn.push_back(colorNames.substr(start,end - start)); start = end + 1; end = colorNames.find(colorDelimiter,start); - } + } // Get the last color. if (!colorNames.empty()) - { + { cn.push_back(colorNames.substr(start,colorNames.size() - start)); - } + } return cn; } @@ -723,20 +723,20 @@ std::vector > ParseSynonyms( std::vector > syn; vtkStdString str; while(end != std::string::npos) - { + { str = synonyms.substr(start,end - start); cn = ParseColorNames(str); syn.push_back(cn); start = end + 2; end = synonyms.find(synonymDelimiter,start); - } + } // Get the last set of synonyms. if(!synonyms.empty()) - { + { str = synonyms.substr(start,end - start); cn = ParseColorNames(str); syn.push_back(cn); - } + } // Sanity check! //for(std::vector >::const_iterator p = // syn.begin(); p != syn.end(); ++p) @@ -855,21 +855,21 @@ bool TestHTMLColorToRGBA() vtkColor4ub outputColor; unsigned int i = 0; while (inputString[0] != '\n' ) - { + { inputString = dataList[i].colorString; expectedOutput = dataList[i].colorVector; outputColor = color->HTMLColorToRGBA(inputString); if (outputColor != vtkColor4ub(expectedOutput)) - { + { vtkGenericWarningMacro( << "Fail: input `" << inputString << "`" << ", found " << outputColor << ", expected " << vtkColor4ub(expectedOutput) << " instead." ); testResult &= false; - } - ++i; } + ++i; + } return testResult; } @@ -897,21 +897,21 @@ bool TestRGBToHTMLColor() const char* expectedOutput = ""; unsigned int i = 0; while ( dataList[i].colorString[0] != '\n' ) - { + { vtkColor3ub inputColor(dataList[i].colorVector); expectedOutput = dataList[i].colorString; outputString = color->RGBToHTMLColor(inputColor); if (outputString.compare(expectedOutput) != 0) - { + { vtkGenericWarningMacro( << "Fail: input `" << inputColor << "`" << ", found '" << outputString << "', expected '" << expectedOutput << "' instead." ); testResult &= false; - } - ++i; } + ++i; + } return testResult; } @@ -941,21 +941,21 @@ bool TestRGBAToHTMLColor() const char* expectedOutput = ""; unsigned int i = 0; while ( dataList[i].colorString[0] != '\n' ) - { + { vtkColor4ub inputColor(dataList[i].colorVector); expectedOutput = dataList[i].colorString; outputString = color->RGBAToHTMLColor(inputColor); if (outputString.compare(expectedOutput) != 0) - { + { vtkGenericWarningMacro( << "Fail: input `" << inputColor << "`" << ", found '" << outputString << "', expected '" << expectedOutput << "' instead." ); testResult &= false; - } - ++i; } + ++i; + } return testResult; } @@ -966,69 +966,69 @@ int TestNamedColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) vtkSmartPointer nc = vtkSmartPointer::New(); bool testResult = TestEmptyColorName(); if ( !testResult ) - { + { vtkGenericWarningMacro( << "Fail: TestNoSuchColor()" ); - } + } testResult &= TestNoSuchColor("no_such_color"); // This color does not exist. if ( !testResult ) - { + { vtkGenericWarningMacro( << "Fail: TestNoSuchColor()" ); - } + } int counter = -1; const int colorsToSkip = 20; std::vector cn = ParseColorNames(nc->GetColorNames()); for ( std::vector::const_iterator p = cn.begin(); p != cn.end(); ++p ) - { + { counter++; // Skip some colors to make testing faster. if ( counter % colorsToSkip != 0 ) - { + { continue; - } + } if ( !TestUnsignedChar(*p) ) - { + { vtkGenericWarningMacro( << "Fail: TestUnsignedChar(), with color " << *p ); testResult &= false; - } + } if ( !TestDouble(*p) ) - { + { vtkGenericWarningMacro( << "Fail: TestDouble(), with color " << *p ); testResult &= false; - } + } if ( !TestDoubleRGB(*p) ) - { + { vtkGenericWarningMacro( << "Fail: TestDoubleRGB(), with color " << *p ); testResult &= false; - } + } if ( !TestUCharToDouble(*p) ) - { + { vtkGenericWarningMacro( << "Fail: TestUCharToDouble(), with color " << *p ); testResult &= false; - } } + } unsigned char ucolor[4]; double dcolor[4]; @@ -1036,33 +1036,33 @@ int TestNamedColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) unsigned char ur = 51; double r = 0.2; for ( size_t i = 0; i < 3; ++i ) - { + { ucolor[i] = static_cast(i+1) * ur; dcolor[i] = (i+1) * r; - } + } ucolor[3] = 0; dcolor[3] = 0; if ( !TestAddingAColor(name,dcolor,ucolor) ) - { + { vtkGenericWarningMacro( << "Fail: TestAddingAColor(), with color " << name ); testResult &= false; - } + } if ( !TestSearchForSynonyms() ) - { + { vtkGenericWarningMacro( << "Fail: TestSearchForSynonyms() - incorrect number of synonyms found, " << "expected " << NUMBER_OF_SYNONYMS << " instead." ); testResult &= false; - } + } if ( static_cast(cn.size()) != NUMBER_OF_COLORS ) - { + { vtkGenericWarningMacro( << "Fail: Incorrect number of colors" << "found " << @@ -1070,11 +1070,11 @@ int TestNamedColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << NUMBER_OF_COLORS << " instead." ); testResult &= false; - } + } nc->ResetColors(); if ( nc->GetNumberOfColors() != NUMBER_OF_COLORS ) - { + { vtkGenericWarningMacro( << "Fail: GetNumberOfColors(), incorrect number of colors" << "found " << @@ -1082,13 +1082,13 @@ int TestNamedColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << NUMBER_OF_COLORS << " instead." ); testResult &= false; - } + } vtkSmartPointer vs = vtkSmartPointer::New(); nc->GetColorNames(vs); if ( vs->GetNumberOfValues() != NUMBER_OF_COLORS ) - { + { vtkGenericWarningMacro( << "Fail: GetColorNames(), incorrect number of colors" << "found " << @@ -1096,48 +1096,48 @@ int TestNamedColors(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) << NUMBER_OF_COLORS << " instead." ); testResult &= false; - } + } std::ostringstream os; nc->PrintSelf(os,vtkIndent(2)); //std::cout << os.str() << std::endl; if ( static_cast(os.str().size()) != PRINT_SELF_STRING_SIZE ) - { + { vtkGenericWarningMacro( << "Fail: PrintSelf() - a string of size " << PRINT_SELF_STRING_SIZE << " was expected, got " << os.str().size() << " instead." ); testResult &= false; - } + } testResult &= TestHTMLColorToRGBA(); if ( !testResult ) - { + { vtkGenericWarningMacro( << "Fail: TestHTMLColorToRGBA()" ); - } + } testResult &= TestRGBToHTMLColor(); if ( !testResult ) - { + { vtkGenericWarningMacro( << "Fail: TestRGBToHTMLColor()" ); - } + } testResult &= TestRGBAToHTMLColor(); if ( !testResult ) - { + { vtkGenericWarningMacro( << "Fail: TestRGBAToHTMLColor()" ); - } + } if ( !testResult ) - { + { return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/Common/Color/vtkColorSeries.cxx b/Common/Color/vtkColorSeries.cxx index 1751f5d47e1..c465d7ca6ee 100644 --- a/Common/Color/vtkColorSeries.cxx +++ b/Common/Color/vtkColorSeries.cxx @@ -305,27 +305,27 @@ guidance on attribution and permissions: vtkTypeUInt32* color = colors; vtkColorSeriesPalette* pal; for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); ++i) - { + { int start = sizes[i][0]; int stop = sizes[i][1]; int step = start > stop ? -1 : 1; for (int n = start; n != stop + step; n += step) - { + { int paletteIndex = *(color++); pal = &(this->Palettes[paletteIndex]); std::ostringstream os; os << names[i]; if (start != stop) - { + { os << " (" << n << ")"; - } + } pal->Name = os.str(); for (int j = 0; j < n; ++j) - { + { pal->Colors.push_back(vtkColor3ubFromHex3(*(color++))); - } } } + } this->Colors = 0; this->Palette = vtkColorSeries::SPECTRUM; this->Colors = &(this->Palettes[this->Palette].Colors); @@ -346,13 +346,13 @@ int vtkColorSeries::Private::SetSchemeByName( int idx = 0; std::vector::iterator it; for (it = this->Palettes.begin(); it != this->Palettes.end(); ++it, ++idx) - { + { if (it->Name == name) - { + { this->SetScheme(idx); return idx; - } } + } // OK, we could not find such a palette. Create one. modified = true; vtkColorSeriesPalette blank; @@ -397,15 +397,15 @@ void vtkColorSeries::PrintSelf(ostream &os, vtkIndent indent) void vtkColorSeries::SetColorScheme(int scheme) { if (this->Storage->Palette == scheme) - { + { return; - } + } if (scheme < 0 || scheme >= this->GetNumberOfColorSchemes()) - { + { vtkWarningMacro(<< "Scheme " << scheme << " out of range. Ignoring."); return; - } + } this->Storage->SetScheme(scheme); this->Modified(); @@ -417,9 +417,9 @@ int vtkColorSeries::SetColorSchemeByName(const vtkStdString& schemeName) bool modified; int index = this->Storage->SetSchemeByName(schemeName, modified); if (modified) - { + { this->Modified(); - } + } return index; } @@ -444,16 +444,16 @@ void vtkColorSeries::SetColorSchemeName(const vtkStdString& name) // SetColorSchemeByName() so users can override // system defaults? if ( name.empty() ) - { + { return; - } + } this->CopyOnWrite(); if (this->Storage->Palettes[this->Storage->Palette].Name != name) - { + { this->Storage->Palettes[this->Storage->Palette].Name = name; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -479,13 +479,13 @@ void vtkColorSeries::SetNumberOfColors(int numColors) vtkColor3ub vtkColorSeries::GetColor(int index) const { if (index >=0 && index < static_cast(this->Storage->Colors->size())) - { + { return (*this->Storage->Colors)[index]; - } + } else - { + { return vtkColor3ub(0,0,0); - } + } } //----------------------------------------------------------------------------- @@ -506,11 +506,11 @@ vtkColor3ub vtkColorSeries::GetColorRepeating(int index) const void vtkColorSeries::SetColor(int index, const vtkColor3ub &color) { if (index >=0 && index < static_cast(this->Storage->Colors->size())) - { + { this->CopyOnWrite(); (*this->Storage->Colors)[index] = color; this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -525,23 +525,23 @@ void vtkColorSeries::AddColor(const vtkColor3ub &color) void vtkColorSeries::InsertColor(int index, const vtkColor3ub &color) { if (index >=0 && index < static_cast(this->Storage->Colors->size())) - { + { this->CopyOnWrite(); this->Storage->Colors->insert( this->Storage->Colors->begin() + index, color); this->Modified(); - } + } } //----------------------------------------------------------------------------- void vtkColorSeries::RemoveColor(int index) { if (index >=0 && index < static_cast(this->Storage->Colors->size())) - { + { this->CopyOnWrite(); this->Storage->Colors->erase(this->Storage->Colors->begin() + index); this->Modified(); - } + } } //----------------------------------------------------------------------------- @@ -556,9 +556,9 @@ void vtkColorSeries::ClearColors() void vtkColorSeries::DeepCopy(vtkColorSeries* colors) { if (! colors) - { + { return; - } + } this->Storage->Palettes = colors->Storage->Palettes; this->Storage->Palette = colors->Storage->Palette; @@ -571,16 +571,16 @@ void vtkColorSeries::DeepCopy(vtkColorSeries* colors) void vtkColorSeries::BuildLookupTable(vtkLookupTable* lkup, int lutIndexing) { if (lkup) - { + { lkup->SetNumberOfTableValues(this->GetNumberOfColors()); lkup->SetIndexedLookup((lutIndexing == ORDINAL) ? 0 : 1); for (int i = 0; i < this->GetNumberOfColors(); ++i) - { + { vtkColor3ub colr = this->GetColor(i); lkup->SetTableValue( i, colr.GetRed()/255., colr.GetGreen()/255., colr.GetBlue()/255., 1.); - } } + } } //----------------------------------------------------------------------------- @@ -597,7 +597,7 @@ void vtkColorSeries::CopyOnWrite() // If the current scheme is predefined, copy it to a new, custom scheme. int prevScheme = this->Storage->Palette; if (prevScheme < CUSTOM) - { + { int nextScheme = static_cast(this->Storage->Palettes.size()); vtkColorSeriesPalette blank; blank.Name = this->Storage->Palettes[prevScheme].Name + " copy"; @@ -605,5 +605,5 @@ void vtkColorSeries::CopyOnWrite() this->Storage->SetScheme(nextScheme); *this->Storage->Colors = this->Storage->Palettes[prevScheme].Colors; this->Modified(); - } + } } diff --git a/Common/Color/vtkColorSeries.h b/Common/Color/vtkColorSeries.h index 6ae6484f746..8ae2f97cd5f 100644 --- a/Common/Color/vtkColorSeries.h +++ b/Common/Color/vtkColorSeries.h @@ -189,7 +189,7 @@ class VTKCOMMONCOLOR_EXPORT vtkColorSeries : public vtkObject BREWER_QUALITATIVE_SET3, /// User specified color scheme. CUSTOM - }; + }; /** * An enum defining how lookup tables should be used: either as a diff --git a/Common/Color/vtkNamedColors.cxx b/Common/Color/vtkNamedColors.cxx index b1d6d3bd859..1a35b636458 100644 --- a/Common/Color/vtkNamedColors.cxx +++ b/Common/Color/vtkNamedColors.cxx @@ -57,19 +57,19 @@ class vtkNamedColorsDataStore void GetColor(const vtkStdString & name, vtkColor4ub & color) { for(int i = 0; i < 3; ++i) - { + { color[i] = 0; - } + } color[3] = 255; if ( !name.empty() ) - { + { vtkStdString s = this->ToLowercase(name); std::map::iterator p = this->colorMap.find(s); if ( p != this->colorMap.end() ) - { + { color = p->second; - } } + } } //----------------------------------------------------------------------------- @@ -82,9 +82,9 @@ class vtkNamedColorsDataStore vtkColor4ub c; this->GetColor(name,c); for(int i = 0; i < c.GetSize(); ++i) - { + { color[i] = static_cast(c[i] / 255.0); - } + } } //----------------------------------------------------------------------------- @@ -97,9 +97,9 @@ class vtkNamedColorsDataStore vtkColor4ub c; this->GetColor(name,c); for(int i = 0; i < color.GetSize(); ++i) - { + { color[i] = c[i]; - } + } } //----------------------------------------------------------------------------- @@ -112,9 +112,9 @@ class vtkNamedColorsDataStore vtkColor4d c; this->GetColor(name,c); for(int i = 0; i < color.GetSize(); ++i) - { + { color[i] = c[i]; - } + } } //----------------------------------------------------------------------------- @@ -125,10 +125,10 @@ class vtkNamedColorsDataStore void SetColor(const vtkStdString & name, const vtkColor4ub & color) { if ( !name.empty() && color.GetSize() == 4 ) - { + { vtkStdString s = this->ToLowercase(name); this->colorMap[s] = color; - } + } } //----------------------------------------------------------------------------- @@ -139,7 +139,7 @@ class vtkNamedColorsDataStore void SetColor(const vtkStdString & name, const vtkColor4d & color) { if ( !name.empty() && color.GetSize() == 4 ) - { + { vtkStdString s = this->ToLowercase(name); unsigned char r, g, b, a; r = static_cast(color.GetRed() * 255.0); @@ -147,7 +147,7 @@ class vtkNamedColorsDataStore b = static_cast(color.GetBlue() * 255.0); a = static_cast(color.GetAlpha() * 255.0); this->colorMap[s] = vtkColor4ub(r,g,b,a); - } + } } //----------------------------------------------------------------------------- @@ -159,9 +159,9 @@ class vtkNamedColorsDataStore { vtkColor4ub c; for(int i = 0; i < 3; ++i) - { + { c[i] = color[i]; - } + } c[3] = 255; this->SetColor(name,c); } @@ -175,9 +175,9 @@ class vtkNamedColorsDataStore { vtkColor4d c; for(int i = 0; i < 3; ++i) - { + { c[i] = color[i]; - } + } c[3] = 1.0; this->SetColor(name,c); } @@ -188,14 +188,14 @@ class vtkNamedColorsDataStore void RemoveColor(const vtkStdString & name) { if (!name.empty()) - { + { vtkStdString s = this->ToLowercase(name); std::map::iterator p = this->colorMap.find(s); if ( p != this->colorMap.end() ) - { + { this->colorMap.erase(p); - } } + } } //----------------------------------------------------------------------------- @@ -214,9 +214,9 @@ std::vector GetColorNames() for(std::map::const_iterator p = this->GetColorMap()->begin(); p != this->GetColorMap()->end(); ++p ) - { + { colorNames.push_back(p->first); - } + } return colorNames; } @@ -230,50 +230,50 @@ std::vector > GetSynonyms() std::map > synonyms; for ( std::vector::const_iterator p = cn.begin(); p != cn.end(); ++p ) - { + { vtkColor4ub vu; this->GetColor(*p,vu); std::vector duplicates; for ( std::map::const_iterator q = this->GetColorMap()->begin(); q != this->GetColorMap()->end(); ++q ) - { + { if( *p != q->first && vu.Compare( q->second, 1 ) ) - { + { duplicates.push_back(q->first); - } } + } if ( !duplicates.empty() ) - { + { bool alreadyInMap = false; for( std::vector::const_iterator r = duplicates.begin(); r != duplicates.end(); ++r) - { + { if( synonyms.find(*r) != synonyms.end() ) - { + { alreadyInMap = true; break; - } } + } if ( !alreadyInMap ) - { + { synonyms[*p] = duplicates; - } } } + } std::vector > retVec; for(std::map >::const_iterator p = synonyms.begin(); p != synonyms.end(); ++p) - { + { std::vector vstr; vstr.push_back(p->first); for(std::vector::const_iterator q = p->second.begin(); q!= p->second.end(); ++q) - { + { vstr.push_back(*q); - } - retVec.push_back(vstr); } + retVec.push_back(vstr); + } return retVec; } @@ -659,7 +659,7 @@ static const char *colorTable[] = // Here we fill the color map. size_t colorTableSz = sizeof(colorTable)/sizeof(colorTable[0]); for (size_t i = 0; i < colorTableSz; ++i) - { + { std::vector color; vtkStdString s = colorTable[i]; size_t idx = s.find(','); @@ -682,7 +682,7 @@ static const char *colorTable[] = t = s.substr(start,s.size() - start); // Alpha color.push_back(static_cast(atoi(t.c_str()))); this->colorMap[name] = vtkColor4ub(color[0],color[1],color[2],color[3]); - } + } } private: @@ -762,36 +762,36 @@ bool vtkColorStringParser::Parse(const vtkStdString& colorString) this->StateGood = (pos != vtkStdString::npos); if (this->StateGood) - { + { if (color[pos] == '#') - { + { // Trim trailing spaces. vtkStdString::size_type last = color.find_last_not_of(" \t"); this->HexStringToRGBA(color.substr(pos + 1, last - pos)); - } + } else if (color.compare(pos, 4, "rgba") == 0) - { + { this->RGBAFuncStringToRGBA(color, pos+4, 4); - } + } else if (color.compare(pos, 3, "rgb") == 0) - { + { this->RGBAFuncStringToRGBA(color, pos+3, 3); this->Color[3] = 255; - } + } else - { + { this->StateGood = this->NamedColors->ColorExists(color); if (this->StateGood) - { + { this->NamedColors->GetColor(color, this->Color); - } } } + } if (!this->StateGood) - { + { this->Color.Set(0, 0, 0, 0); - } + } return this->StateGood; } @@ -799,13 +799,13 @@ bool vtkColorStringParser::Parse(const vtkStdString& colorString) unsigned char clip(long int value) { if (value < 0) - { + { value = 0; - } + } else if (value > 255) - { + { value = 255; - } + } return static_cast(value); } @@ -813,13 +813,13 @@ unsigned char clip(long int value) double clip(double value) { if (value < 0.0) - { + { value = 0.0; - } + } else if (value > 1.0) - { + { value = 1.0; - } + } return value; } @@ -840,25 +840,25 @@ void vtkColorStringParser::HexStringToRGBA(vtkStdString color) this->StateGood = (pos == vtkStdString::npos); if (this->StateGood) - { + { if (color.size() == 3) // #RGB -> #RRGGBB - { + { color.resize(6); vtkStdString::size_type i = 3, j = 6; do - { + { color[--j] = color[--i]; color[--j] = color[i]; - } while (i != 0); - } + } while (i != 0); + } else if (color.size() != 6) - { + { this->StateGood = false; - } + } // Parse hex bytes. if (this->StateGood) - { + { std::istringstream istr; int c; for (unsigned int i = 0; i < 3; ++i) @@ -869,8 +869,8 @@ void vtkColorStringParser::HexStringToRGBA(vtkStdString color) istr.clear(); } this->Color[3] = 255; - } } + } } //------------------------------------------------------------------------------ @@ -895,13 +895,13 @@ void vtkColorStringParser::RGBAFuncStringToRGBA(vtkStdString color, for (vtkStdString::size_type i = pos + 1; (delimiterCount < argCount) && (i < color.size()); ++i) - { + { if (color[i] == ',') - { + { color[i] = ' '; ++delimiterCount; - } } + } this->StateGood = (delimiterCount + 1 == argCount); // Parse arguments. @@ -910,50 +910,50 @@ void vtkColorStringParser::RGBAFuncStringToRGBA(vtkStdString color, char** final = &end; if (!usePercentage) - { + { long int value; for (unsigned int i = 0; this->StateGood && (i < 3); ++i) - { + { value = strtol(start, final, 10); this->Color[i] = clip(value); this->StateGood = (start != end); start = end; - } } + } else - { + { double value; for (unsigned int i = 0; this->StateGood && (i < 3); ++i) - { + { value = strtod(start, final); this->Color[i] = static_cast(255 * clipPercentage(value)); this->StateGood = (start != end && *end == '%'); start = ++end; - } } + } // Parse the alpha value if needed. if (this->StateGood && argCount == 4) - { + { double value = strtod(start, final); this->Color[3] = static_cast(255 * clip(value)); this->StateGood = (start != end); - } + } // Parse ')'. if (this->StateGood) - { + { pos = end - color.c_str(); pos = color.find_first_not_of(" \t", pos); this->StateGood = (pos != vtkStdString::npos && color[pos] == ')'); - } + } // Left characters must be only trailing spaces or the string is not valid. if (this->StateGood) - { + { pos = color.find_first_not_of(" \t", pos + 1); this->StateGood = (pos == vtkStdString::npos); - } + } } @@ -982,19 +982,19 @@ void vtkNamedColors::PrintSelf(ostream &os, vtkIndent indent) for ( std::map::const_iterator p = this->Colors->GetColorMap()->begin(); p != this->Colors->GetColorMap()->end(); ++p ) - { + { os << indent << ": " << p->first << "("; if (p->second.GetSize() == 4) - { + { int r = p->second.GetRed(); int g = p->second.GetGreen(); int b = p->second.GetBlue(); int a = p->second.GetAlpha(); os << setw(3) << r << "," << setw(3) << g << ","<< setw(3) << b <<"," << setw(3) << a; - } - os << ")" << endl; } + os << ")" << endl; + } } //----------------------------------------------------------------------------- @@ -1008,13 +1008,13 @@ vtkStdString vtkNamedColors::GetColorNames() // Now just iterate through the map getting the color names. for(std::vector::const_iterator p = cnv.begin(); p != cnv.end(); ++p ) - { + { colorNames += *p; if (p != lastItr) - { + { colorNames += "\n"; - } } + } return colorNames; } @@ -1025,9 +1025,9 @@ void vtkNamedColors::GetColorNames(vtkStringArray * colorNames) // Now just iterate through the map getting the color names. for(std::vector::const_iterator p = cnv.begin(); p != cnv.end(); ++p ) - { + { colorNames->InsertNextValue(*p); - } + } } //----------------------------------------------------------------------------- @@ -1039,25 +1039,25 @@ vtkStdString vtkNamedColors::GetSynonyms() --synLast; for(std::vector >::const_iterator p = syn.begin(); p != syn.end(); ++p) - { + { // Get the last element in the vector. std::vector::const_iterator strLast = p->end(); --strLast; for(std::vector::const_iterator q = p->begin(); q!= p->end(); ++q) - { + { synonyms += *q; if(q != strLast) - { + { synonyms += "\n"; - } } + } if (p != synLast) - { + { synonyms += "\n\n"; - } } + } return synonyms; } @@ -1107,9 +1107,9 @@ void vtkNamedColors::GetColor(const vtkStdString & name, unsigned char rgba[4]) vtkColor4ub color; this->Colors->GetColor(name,color); for(int i = 0; i < color.GetSize(); ++i) - { + { rgba[i] = color[i]; - } + } } //----------------------------------------------------------------------------- @@ -1144,9 +1144,9 @@ void vtkNamedColors::GetColor(const vtkStdString & name, double rgba[4]) vtkColor4d color; this->Colors->GetColor(name,color); for(int i = 0; i < color.GetSize(); ++i) - { + { rgba[i] = color[i]; - } + } } //----------------------------------------------------------------------------- @@ -1188,9 +1188,9 @@ void vtkNamedColors::GetColorRGB(const vtkStdString & name, double rgb[3]) vtkColor3d color; this->Colors->GetColor(name,color); for(int i = 0; i < color.GetSize(); ++i) - { + { rgb[i] = color[i]; - } + } } //----------------------------------------------------------------------------- @@ -1224,9 +1224,9 @@ void vtkNamedColors::SetColor(const vtkStdString & name, { vtkColor4ub v; for ( int i = 0; i < v.GetSize(); ++i ) - { + { v[i] = rgba[i]; - } + } this->Colors->SetColor(name,v); } @@ -1262,9 +1262,9 @@ void vtkNamedColors::SetColor(const vtkStdString & name, const double rgba[4]) { vtkColor4d v; for ( int i = 0; i < v.GetSize(); ++i ) - { + { v[i] = rgba[i]; - } + } this->Colors->SetColor(name,v); } @@ -1274,9 +1274,9 @@ void vtkNamedColors::SetColor(const vtkStdString & name, { vtkColor4d v; for ( int i = 0; i < v.GetSize(); ++i ) - { + { v[i] = rgba[i]; - } + } this->Colors->SetColor(name,v); } @@ -1291,9 +1291,9 @@ void vtkNamedColors::SetColor(const vtkStdString & name, void vtkNamedColors::RemoveColor(const vtkStdString & name) { if (!name.empty()) - { + { this->Colors->RemoveColor(name); - } + } } //----------------------------------------------------------------------------- @@ -1319,14 +1319,14 @@ void vtkNamedColors::SetColor(const vtkStdString & name, const vtkStdString & htmlString) { if (!name.empty()) - { + { vtkColor4ub noColor(0, 0, 0, 0); vtkColor4ub color = this->HTMLColorToRGBA(htmlString); if (color != noColor) - { + { this->SetColor(name, color); - } } + } } //----------------------------------------------------------------------------- diff --git a/Common/ComputationalGeometry/Testing/Cxx/UnitTestParametricSpline.cxx b/Common/ComputationalGeometry/Testing/Cxx/UnitTestParametricSpline.cxx index 9d190f2f380..6bd8dee935e 100644 --- a/Common/ComputationalGeometry/Testing/Cxx/UnitTestParametricSpline.cxx +++ b/Common/ComputationalGeometry/Testing/Cxx/UnitTestParametricSpline.cxx @@ -56,13 +56,13 @@ void GeneratePoints(int npts, vtkSmartPointer &points) double deltaX = vtkMath::Pi() * 2.0 / (npts - 1); double deltaZ = 2.0 / (npts - 1); for (int n = 0; n < npts; ++n) - { + { double x[3]; x[0] = -vtkMath::Pi() + n * deltaX; x[1] = std::sin(x[0]); x[2] = -1.0 + n * deltaZ; points->SetPoint(n, x[0], x[1], x[2]); - } + } } int TestSetPoints(vtkPoints *points, bool closed) @@ -72,13 +72,13 @@ int TestSetPoints(vtkPoints *points, bool closed) vtkSmartPointer pspline = vtkSmartPointer::New(); if (closed) - { + { pspline->ClosedOn(); - } + } else - { + { pspline->ClosedOff(); - } + } int npts = points->GetNumberOfPoints(); pspline->SetNumberOfPoints(npts); @@ -91,37 +91,37 @@ int TestSetPoints(vtkPoints *points, bool closed) double xm1[3] = {0.0,0.0,0.0}; double x[3]; for (int n = 0; n < npts; ++n) - { + { points->GetPoint(n, x); pspline->SetPoint(n, x[0], x[1], x[2]); if (n > 0) - { + { length += std::sqrt(vtkMath::Distance2BetweenPoints(x, xm1)); - } + } xm1[0] = x[0]; xm1[1] = x[1]; xm1[2] = x[2]; - } + } if (closed) - { + { points->GetPoint(0, x); points->GetPoint(npts - 1, xm1); length += std::sqrt(vtkMath::Distance2BetweenPoints(x, xm1)); - } + } double tolerance = 4.0*std::numeric_limits::epsilon(); pspline->ParameterizeByLengthOff(); for (int n = 0; n < npts; ++n) - { + { double t[3]; if (closed) - { + { t[0] = static_cast(n) / static_cast((npts)); - } + } else - { + { t[0] = static_cast(n) / static_cast((npts - 1)); - } + } t[1] = t[2] = 0.0; points->GetPoint(n, x); @@ -131,15 +131,15 @@ int TestSetPoints(vtkPoints *points, bool closed) if (!vtkMathUtilities::FuzzyCompare(x[0], result[0], tolerance) || !vtkMathUtilities::FuzzyCompare(x[1], result[1], tolerance) || !vtkMathUtilities::FuzzyCompare(x[2], result[2], tolerance)) - { + { std::cout << "TestSetPoints(by point id): Expected " << x[0] << ", " << x[1] << ", " << x[2] << " but got " << result[0] << ", " << result[1] << ", " << result[2] << std::endl; ++status; - } } + } // Test with externally created points tolerance = 8.0*std::numeric_limits::epsilon(); @@ -149,13 +149,13 @@ int TestSetPoints(vtkPoints *points, bool closed) length = 0.0; for (int n = 0; n < npts; ++n) - { + { points->GetPoint(n, x); if (n > 0) - { + { length += std::sqrt(vtkMath::Distance2BetweenPoints(x, xm1)); - } + } double t[3]; t[0] = length / totalLength; t[1] = t[2] = 0.0; @@ -165,18 +165,18 @@ int TestSetPoints(vtkPoints *points, bool closed) if (!vtkMathUtilities::FuzzyCompare(x[0], result[0], tolerance) || !vtkMathUtilities::FuzzyCompare(x[1], result[1], tolerance) || !vtkMathUtilities::FuzzyCompare(x[2], result[2], tolerance)) - { + { std::cout << "TestSetPoints(by length): Expected " << x[0] << ", " << x[1] << ", " << x[2] << " but got " << result[0] << ", " << result[1] << ", " << result[2] << std::endl; ++status; - } + } xm1[0] = x[0]; xm1[1] = x[1]; xm1[2] = x[2]; - } + } knots->Delete(); return status; @@ -199,43 +199,43 @@ int TestErrors() pspline->Evaluate(x, result, 0); // Check for model bounds error if (errorObserver->GetError()) - { + { std::cout << "Caught expected error: " << errorObserver->GetErrorMessage(); - } + } else - { + { std::cout << "Failed to catch expected 'Please specify points' error" << std::endl; ++status; - } + } errorObserver->Clear(); pspline->SetNumberOfPoints(0); pspline->EvaluateScalar(x, 0, 0); if (errorObserver->GetError()) - { + { std::cout << "Caught expected error: " << errorObserver->GetErrorMessage(); - } + } else - { + { std::cout << "Failed to catch expected 'Please specify at least one point' error" << std::endl; ++status; - } + } errorObserver->Clear(); pspline->SetXSpline(NULL); pspline->Evaluate(x, result, 0); if (errorObserver->GetError()) - { + { std::cout << "Caught expected error: " << errorObserver->GetErrorMessage(); - } + } else - { + { std::cout << "Failed to catch expected 'Please specify spline' error" << std::endl; ++status; - } + } errorObserver->Clear(); return status; @@ -248,51 +248,51 @@ int TestSetGet() vtkSmartPointer::New(); if (pspline->GetDimension() != 1) - { + { std::cout << "GetDimension: expected 1 but got " << pspline->GetDimension()<< std::endl; ++status; - } + } if (pspline->GetParameterizeByLength() != 1) - { + { std::cout << "GetParameterizeByLength: expected 1 but got " << pspline->GetParameterizeByLength()<< std::endl; ++status; - } + } if (pspline->GetPoints() != NULL) - { + { std::cout << "GetPoints: Expected NULL but got " << pspline->GetPoints() << std::endl; ++status; - } + } std::string className; className = pspline->GetXSpline()->GetClassName(); if (className != "vtkCardinalSpline") - { + { std::cout << "GetXSpline: Expected " << "vtkCardinalSpline" << " but got " << className << std::endl; ++status; - } + } className = pspline->GetYSpline()->GetClassName(); if (className != "vtkCardinalSpline") - { + { std::cout << "GetYSpline: Expected " << "vtkCardinalSpline" << " but got " << className << std::endl; ++status; - } + } className = pspline->GetZSpline()->GetClassName(); if (className != "vtkCardinalSpline") - { + { std::cout << "GetZSpline: Expected " << "vtkCardinalSpline" << " but got " << className << std::endl; ++status; - } + } // Now change the spline tyeps vtkSmartPointer xSpline = @@ -300,36 +300,36 @@ int TestSetGet() pspline->SetXSpline(xSpline); className = pspline->GetXSpline()->GetClassName(); if (className != "vtkKochanekSpline") - { + { std::cout << "GetXSpline: Expected " << "vtkKochanekSpline" << " but got " << className << std::endl; ++status; - } + } vtkSmartPointer ySpline = vtkSmartPointer::New(); pspline->SetYSpline(ySpline); className = pspline->GetYSpline()->GetClassName(); if (className != "vtkKochanekSpline") - { + { std::cout << "GetYSpline: Expected " << "vtkKochanekSpline" << " but got " << className << std::endl; ++status; - } + } vtkSmartPointer zSpline = vtkSmartPointer::New(); pspline->SetZSpline(zSpline); className = pspline->GetZSpline()->GetClassName(); if (className != "vtkKochanekSpline") - { + { std::cout << "GetZSpline: Expected " << "vtkKochanekSpline" << " but got " << className << std::endl; ++status; - } + } return status; } @@ -357,60 +357,60 @@ int TestConstraints() if (pspline->GetXSpline()->GetLeftConstraint() != pspline->GetLeftConstraint()) - { + { std::cout << "GetXSpline->GetLeftContraint: Expected " << pspline->GetLeftConstraint() << " but got " << pspline->GetXSpline()->GetLeftConstraint() << std::endl; ++status; - } + } if (pspline->GetXSpline()->GetLeftValue() != pspline->GetLeftValue()) - { + { std::cout << "GetXSpline->GetLeftValue: Expected " << pspline->GetLeftValue() << " but got " << pspline->GetXSpline()->GetLeftValue() << std::endl; ++status; - } + } if (pspline->GetYSpline()->GetLeftConstraint() != pspline->GetLeftConstraint()) - { + { std::cout << "GetYSpline->GetLeftContraint: Expected " << pspline->GetLeftConstraint() << " but got " << pspline->GetYSpline()->GetLeftConstraint() << std::endl; ++status; - } + } if (pspline->GetYSpline()->GetLeftValue() != pspline->GetLeftValue()) - { + { std::cout << "GetYSpline->GetLeftValue: Expected " << pspline->GetLeftValue() << " but got " << pspline->GetYSpline()->GetLeftValue() << std::endl; ++status; - } + } if (pspline->GetZSpline()->GetLeftConstraint() != pspline->GetLeftConstraint()) - { + { std::cout << "GetZSpline->GetLeftContraint: Expected " << pspline->GetLeftConstraint() << " but got " << pspline->GetZSpline()->GetLeftConstraint() << std::endl; ++status; - } + } if (pspline->GetZSpline()->GetLeftValue() != pspline->GetLeftValue()) - { + { std::cout << "GetZSpline->GetLeftValue: Expected " << pspline->GetLeftValue() << " but got " << pspline->GetZSpline()->GetLeftValue() << std::endl; ++status; - } + } return status; } @@ -426,14 +426,14 @@ int TestMisc() x[2] = 0.0; if (pspline->EvaluateScalar(x, NULL, NULL) != x[0]) - { + { std::cout << "EvaluateScalar: Expected " << x[0] << " but got " << pspline->EvaluateScalar(x, NULL, NULL) << std::endl; ++status; - } + } return status; } void TestPrint() diff --git a/Common/ComputationalGeometry/vtkCardinalSpline.cxx b/Common/ComputationalGeometry/vtkCardinalSpline.cxx index 43b844890b7..a3cb1d59062 100644 --- a/Common/ComputationalGeometry/vtkCardinalSpline.cxx +++ b/Common/ComputationalGeometry/vtkCardinalSpline.cxx @@ -36,34 +36,34 @@ double vtkCardinalSpline::Evaluate (double t) // check to see if we need to recompute the spline if (this->ComputeTime < this->GetMTime ()) - { + { this->Compute (); - } + } // make sure we have at least 2 points int size = this->PiecewiseFunction->GetSize (); if (size < 2) - { + { return 0.0; - } + } intervals = this->Intervals; coefficients = this->Coefficients; if ( this->Closed ) - { + { size = size + 1; - } + } // clamp the function at both ends if (t < intervals[0]) - { + { t = intervals[0]; - } + } if (t > intervals[size - 1]) - { + { t = intervals[size - 1]; - } + } // find pointer to cubic spline coefficient using bisection method index = this->FindIndex(size,t); @@ -93,10 +93,10 @@ void vtkCardinalSpline::Compute () size = this->PiecewiseFunction->GetSize (); if(size < 2) - { + { vtkErrorMacro("Cannot compute a spline with less than 2 points. # of points is: " << size); return; - } + } // copy the independent variables. Note that if the spline // is closed the first and last point are assumed repeated - @@ -104,13 +104,13 @@ void vtkCardinalSpline::Compute () delete [] this->Intervals; if ( !this->Closed ) - { + { this->Intervals = new double[size]; ts = this->PiecewiseFunction->GetDataPointer (); for (i = 0; i < size; i++) - { + { this->Intervals[i] = *(ts + 2*i); - } + } // allocate memory for work arrays work = new double[size]; @@ -128,33 +128,33 @@ void vtkCardinalSpline::Compute () // get the dependent variable values xs = this->PiecewiseFunction->GetDataPointer () + 1; for (int j = 0; j < size; j++) - { + { *(dependent + j) = *(xs + 2*j); - } + } this->Fit1D (size, this->Intervals, dependent, work, (double (*)[4])coefficients, this->LeftConstraint, this->LeftValue, this->RightConstraint, this->RightValue); - } + } else //add extra "fictitious" point to close loop - { + { size = size + 1; this->Intervals = new double[size]; ts = this->PiecewiseFunction->GetDataPointer (); for (i = 0; i < size-1; i++) - { + { this->Intervals[i] = *(ts + 2*i); - } + } if ( this->ParametricRange[0] != this->ParametricRange[1] ) - { + { this->Intervals[size-1] = this->ParametricRange[1]; - } + } else - { + { this->Intervals[size-1] = this->Intervals[size-2] + 1.0; - } + } // allocate memory for work arrays work = new double[size]; @@ -172,14 +172,14 @@ void vtkCardinalSpline::Compute () // get the dependent variable values xs = this->PiecewiseFunction->GetDataPointer () + 1; for (int j = 0; j < size-1; j++) - { + { *(dependent + j) = *(xs + 2*j); - } + } dependent[size-1] = *xs; this->FitClosed1D (size, this->Intervals, dependent, work, (double (*)[4])coefficients); - } + } // free the work array and dependent variable storage delete [] work; @@ -204,7 +204,7 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, // develop constraint at leftmost point. switch (leftConstraint) - { + { case 0: // desired slope at leftmost point is derivative from two points coefficients[0][1] = 1.0; @@ -236,11 +236,11 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, default: assert("check: impossible case." && 0); // reaching this line is a bug. break; - } + } // develop body of band matrix. for (k = 1; k < size - 1; k++) - { + { xlk = x[k] - x[k-1]; xlkp = x[k+1] - x[k]; coefficients[k][0] = xlkp; @@ -248,12 +248,12 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, coefficients[k][2] = xlk; work[k] = 3.0 * (((xlkp * (y[k] - y[k-1])) / xlk) + ((xlk * (y[k+1] - y[k])) / xlkp)); - } + } // develop constraint at rightmost point. switch (rightConstraint) - { + { case 0: // desired slope at leftmost point is derivative from two points coefficients[size - 1][0] = 0.0; @@ -287,7 +287,7 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, default: assert("check: impossible case." && 0); // reaching this line is a bug. break; - } + } // solve resulting set of equations. coefficients[0][2] = coefficients[0][2] / coefficients[0][1]; @@ -295,25 +295,25 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, coefficients[size-1][2] = 0.0; for (k = 1; k < size; k++) - { + { coefficients[k][1] = coefficients[k][1] - (coefficients[k][0] * coefficients[k-1][2]); coefficients[k][2] = coefficients[k][2] / coefficients[k][1]; work[k] = (work[k] - (coefficients[k][0] * work[k-1])) / coefficients[k][1]; - } + } for (k = size - 2; k >= 0; k--) - { + { work[k] = work[k] - (coefficients[k][2] * work[k+1]); - } + } // the column vector work now contains the first // derivative of the spline function at each joint. // compute the coefficients of the cubic between // each pair of joints. for (k = 0; k < size - 1; k++) - { + { b = x[k+1] - x[k]; coefficients[k][0] = y[k]; coefficients[k][1] = work[k]; @@ -321,7 +321,7 @@ void vtkCardinalSpline::Fit1D (int size, double *x, double *y, (work[k+1] + 2.0 * work[k]) / b; coefficients[k][3] = (2.0 * (y[k] - y[k+1])) / (b * b * b) + (work[k+1] + work[k]) / (b * b); - } + } // the coefficients of a fictitious nth cubic // are evaluated. This may simplify @@ -354,7 +354,7 @@ void vtkCardinalSpline::FitClosed1D (int size, double *x, double *y, // develop body of band matrix. // for (k = 1; k < N; k++) - { + { xlk = x[k] - x[k-1]; xlkp = x[k+1] - x[k]; coefficients[k][0] = xlkp; @@ -362,7 +362,7 @@ void vtkCardinalSpline::FitClosed1D (int size, double *x, double *y, coefficients[k][2] = xlk; work[k] = 3.0 * (((xlkp * (y[k] - y[k-1])) / xlk) + ((xlk * (y[k+1] - y[k])) / xlkp)); - } + } xlk = x[N] - x[N-1]; xlkp = x[1] - x[0]; @@ -379,7 +379,7 @@ void vtkCardinalSpline::FitClosed1D (int size, double *x, double *y, coefficients[0][3] = 1.0; for (k = 1; k <= N; k++) - { + { coefficients[k][1] = coefficients[k][1] - (coefficients[k][0] * coefficients[k-1][2]); coefficients[k][2] = coefficients[k][2] / coefficients[k][1]; @@ -387,33 +387,33 @@ void vtkCardinalSpline::FitClosed1D (int size, double *x, double *y, / coefficients[k][1]; coefficients[k][3] = (-1.0 * coefficients[k][0] * coefficients[k-1][3]) / coefficients[k][1]; - } + } coefficients[N][0] = 1.0; coefficients[N][1] = 0.0; for (k = N - 1; k > 0; k--) - { + { coefficients[k][0] = coefficients[k][3] - coefficients[k][2] * coefficients[k+1][0]; coefficients[k][1] = work[k] - coefficients[k][2] * coefficients[k+1][1]; - } + } work[0] = work[N] = (dN - cN * coefficients[1][1] - aN * coefficients[N-1][1]) / ( bN + cN * coefficients[1][0] + aN * coefficients[N-1][0]); for (k=1; k < N; k++) - { + { work[k] = coefficients[k][0] * work[N] + coefficients[k][1]; - } + } // the column vector work now contains the first // derivative of the spline function at each joint. // compute the coefficients of the cubic between // each pair of joints. for (k = 0; k < N; k++) - { + { b = x[k+1] - x[k]; coefficients[k][0] = y[k]; coefficients[k][1] = work[k]; @@ -421,7 +421,7 @@ void vtkCardinalSpline::FitClosed1D (int size, double *x, double *y, (work[k+1] + 2.0 * work[k]) / b; coefficients[k][3] = (2.0 * (y[k] - y[k+1])) / (b * b * b) + (work[k+1] + work[k]) / (b * b); - } + } // the coefficients of a fictitious nth cubic @@ -439,9 +439,9 @@ void vtkCardinalSpline::DeepCopy(vtkSpline *s) vtkCardinalSpline *spline = vtkCardinalSpline::SafeDownCast(s); if ( spline != NULL ) - { + { //nothing to do - } + } // Now do superclass this->vtkSpline::DeepCopy(s); diff --git a/Common/ComputationalGeometry/vtkKochanekSpline.cxx b/Common/ComputationalGeometry/vtkKochanekSpline.cxx index e625896b91c..ccc3ac5a741 100644 --- a/Common/ComputationalGeometry/vtkKochanekSpline.cxx +++ b/Common/ComputationalGeometry/vtkKochanekSpline.cxx @@ -41,34 +41,34 @@ double vtkKochanekSpline::Evaluate (double t) // check to see if we need to recompute the spline if (this->ComputeTime < this->GetMTime ()) - { + { this->Compute (); - } + } // make sure we have at least 2 points int size = this->PiecewiseFunction->GetSize (); if (size < 2) - { + { return 0.0; - } + } intervals = this->Intervals; coefficients = this->Coefficients; if ( this->Closed ) - { + { size = size + 1; - } + } // clamp the function at both ends if (t < intervals[0]) - { + { t = intervals[0]; - } + } if (t > intervals[size - 1]) - { + { t = intervals[size - 1]; - } + } // find pointer to cubic spline coefficient index = this->FindIndex(size,t); @@ -97,21 +97,21 @@ void vtkKochanekSpline::Compute () size = this->PiecewiseFunction->GetSize (); if(size < 2) - { + { vtkErrorMacro("Spline requires at least 2 points. # of points is: " <Closed ) - { + { // copy the independent variables delete [] this->Intervals; this->Intervals = new double[size]; ts = this->PiecewiseFunction->GetDataPointer (); for (i = 0; i < size; i++) - { + { this->Intervals[i] = *(ts + 2*i); - } + } // allocate memory for coefficients delete [] this->Coefficients; @@ -126,29 +126,29 @@ void vtkKochanekSpline::Compute () // get the dependent variable values xs = this->PiecewiseFunction->GetDataPointer () + 1; for (int j = 0; j < size; j++) - { + { *(dependent + j) = *(xs + 2*j); - } } + } else //spline is closed, create extra "fictitious" point - { + { size = size + 1; // copy the independent variables delete [] this->Intervals; this->Intervals = new double[size]; ts = this->PiecewiseFunction->GetDataPointer (); for (i = 0; i < size-1; i++) - { + { this->Intervals[i] = *(ts + 2 * i); - } + } if ( this->ParametricRange[0] != this->ParametricRange[1] ) - { + { this->Intervals[size-1] = this->ParametricRange[1]; - } + } else - { + { this->Intervals[size-1] = this->Intervals[size-2] + 1.0; - } + } // allocate memory for coefficients delete [] this->Coefficients; @@ -163,11 +163,11 @@ void vtkKochanekSpline::Compute () // get the dependent variable values xs = this->PiecewiseFunction->GetDataPointer () + 1; for (int j = 0; j < size-1; j++) - { + { *(dependent + j) = *(xs + 2*j); - } - dependent[size-1] = *xs; } + dependent[size-1] = *xs; + } this->Fit1D (size, this->Intervals, dependent, this->DefaultTension, @@ -205,7 +205,7 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, N = size - 1; for (i=1; i < N; i++) - { + { cs = y[i] - y[i-1]; cd = y[i+1] - y[i]; @@ -225,7 +225,7 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, coefficients[i][0] = y[i]; coefficients[i][1] = dd; coefficients[i][2] = ds; - } + } // Calculate the deriviatives at the end points coefficients[0][0] = y[0]; @@ -235,7 +235,7 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, coefficients[N][3] = 0.0; if ( this->Closed ) //the curve is continuous and closed at P0=Pn - { + { cs = y[N] - y[N-1]; cd = y[1] - y[0]; @@ -255,11 +255,11 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, coefficients[0][2] = ds; coefficients[N][1] = dd; coefficients[N][2] = ds; - } + } else //curve is open - { + { switch (leftConstraint) - { + { case 0: // desired slope at leftmost point is leftValue coefficients[0][1] = this->ComputeLeftDerivative(); @@ -281,20 +281,20 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, // times secod derivative at first interior point if ((leftValue > (-2.0 + VTK_EPSILON)) || (leftValue < (-2.0 - VTK_EPSILON))) - { + { coefficients[0][1] = (3*(1 + leftValue)*(y[1] - y[0]) - (1 + 2*leftValue)*coefficients[1][2]) / (2 + leftValue); - } + } else - { + { coefficients[0][1] = 0.0; - } + } break; - } + } switch (rightConstraint) - { + { case 0: // desired slope at rightmost point is rightValue coefficients[N][2] = this->ComputeRightDerivative(); @@ -316,22 +316,22 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, // times secord derivative at last interior point if ((rightValue > (-2.0 + VTK_EPSILON)) || (rightValue < (-2.0 - VTK_EPSILON))) - { + { coefficients[N][2] = (3*(1 + rightValue)*(y[N] - y[N-1]) - (1 + 2*rightValue)*coefficients[N-1][1]) / (2 + rightValue); - } + } else - { + { coefficients[N][2] = 0.0; - } + } break; - } - }//curve is open + } + }//curve is open // Compute the Coefficients for (i=0; i < N; i++) - { + { // // c0 = P ; c1 = DD ; // i i i i @@ -349,7 +349,7 @@ void vtkKochanekSpline::Fit1D (int size, double *x, double *y, + (-2 * coefficients[i][1]) + (-1 * coefficients[i+1][2]); coefficients[i][3] = ( 2 * y[i]) + (-2 * y[i+1]) + ( 1 * coefficients[i][1]) + ( 1 * coefficients[i+1][2]); - } + } } //---------------------------------------------------------------------------- @@ -358,11 +358,11 @@ void vtkKochanekSpline::DeepCopy(vtkSpline *s) vtkKochanekSpline *spline = vtkKochanekSpline::SafeDownCast(s); if ( spline != NULL ) - { + { this->DefaultBias = spline->DefaultBias; this->DefaultTension = spline->DefaultTension; this->DefaultContinuity = spline->DefaultContinuity; - } + } // Now do superclass this->vtkSpline::DeepCopy(s); diff --git a/Common/ComputationalGeometry/vtkParametricBohemianDome.cxx b/Common/ComputationalGeometry/vtkParametricBohemianDome.cxx index 81a5d98c6df..c851579e370 100644 --- a/Common/ComputationalGeometry/vtkParametricBohemianDome.cxx +++ b/Common/ComputationalGeometry/vtkParametricBohemianDome.cxx @@ -22,7 +22,7 @@ vtkParametricBohemianDome::vtkParametricBohemianDome() : A(0.5) , B(1.5) , C(1.0) - { +{ // Preset triangulation parameters this->MinimumU = -vtkMath::Pi(); this->MinimumV = -vtkMath::Pi(); @@ -35,16 +35,16 @@ vtkParametricBohemianDome::vtkParametricBohemianDome() : this->TwistV = 1; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricBohemianDome::~vtkParametricBohemianDome() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricBohemianDome::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -76,16 +76,16 @@ void vtkParametricBohemianDome::Evaluate(double uvw[3], double Pt[3], double Duv Dv[0] = 0.; Dv[1] = -this->B*sinv; Dv[2] = this->C*cosv; - } +} //----------------------------------------------------------------------------// double vtkParametricBohemianDome::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricBohemianDome::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricBour.cxx b/Common/ComputationalGeometry/vtkParametricBour.cxx index dc708288b79..211a0a20191 100644 --- a/Common/ComputationalGeometry/vtkParametricBour.cxx +++ b/Common/ComputationalGeometry/vtkParametricBour.cxx @@ -19,7 +19,7 @@ vtkStandardNewMacro(vtkParametricBour); //----------------------------------------------------------------------------// vtkParametricBour::vtkParametricBour() - { +{ // Preset triangulation parameters this->MinimumU = 0.; this->MinimumV = 0.; @@ -32,16 +32,16 @@ vtkParametricBour::vtkParametricBour() this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricBour::~vtkParametricBour() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricBour::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -66,16 +66,16 @@ void vtkParametricBour::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) Dv[0] = u*(2.*u*cos(v) - 1.)*sin(v); Dv[1] = -u*(cos(v) + u*cos(2.*v)); Dv[2] = -2.*pow(u, 1.5)*sin(1.5*v); - } +} //----------------------------------------------------------------------------// double vtkParametricBour::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricBour::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricCatalanMinimal.cxx b/Common/ComputationalGeometry/vtkParametricCatalanMinimal.cxx index 2e6fc785be1..73a02850ea5 100644 --- a/Common/ComputationalGeometry/vtkParametricCatalanMinimal.cxx +++ b/Common/ComputationalGeometry/vtkParametricCatalanMinimal.cxx @@ -19,7 +19,7 @@ vtkStandardNewMacro(vtkParametricCatalanMinimal); //----------------------------------------------------------------------------// vtkParametricCatalanMinimal::vtkParametricCatalanMinimal() - { +{ // Preset triangulation parameters this->MinimumU = -4.*vtkMath::Pi(); this->MinimumV = -1.5; @@ -32,16 +32,16 @@ vtkParametricCatalanMinimal::vtkParametricCatalanMinimal() this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricCatalanMinimal::~vtkParametricCatalanMinimal() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricCatalanMinimal::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -66,16 +66,16 @@ void vtkParametricCatalanMinimal::Evaluate(double uvw[3], double Pt[3], double D Dv[0] = sin(u)*sinh(v); Dv[1] = -cos(u)*sinh(v); Dv[2] = 2.*sin(u/2.)*cosh(v/2.); - } +} //----------------------------------------------------------------------------// double vtkParametricCatalanMinimal::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricCatalanMinimal::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricEllipsoid.cxx b/Common/ComputationalGeometry/vtkParametricEllipsoid.cxx index 560a3b955cf..f6029101932 100644 --- a/Common/ComputationalGeometry/vtkParametricEllipsoid.cxx +++ b/Common/ComputationalGeometry/vtkParametricEllipsoid.cxx @@ -53,9 +53,9 @@ void vtkParametricEllipsoid::Evaluate(double uvw[3], double Pt[3], double Duvw[9 double *Dv = Duvw + 3; for ( int i = 0; i < 3; ++i) - { + { Pt[i] = Du[i] = Dv[i] = 0; - } + } double cu = cos(u); double su = sin(u); diff --git a/Common/ComputationalGeometry/vtkParametricHenneberg.cxx b/Common/ComputationalGeometry/vtkParametricHenneberg.cxx index af614aba8b2..62394c63d9e 100644 --- a/Common/ComputationalGeometry/vtkParametricHenneberg.cxx +++ b/Common/ComputationalGeometry/vtkParametricHenneberg.cxx @@ -19,7 +19,7 @@ vtkStandardNewMacro(vtkParametricHenneberg); //----------------------------------------------------------------------------// vtkParametricHenneberg::vtkParametricHenneberg() - { +{ // Preset triangulation parameters this->MinimumU = -1.0; this->MinimumV = -vtkMath::Pi()/2.; @@ -32,16 +32,16 @@ vtkParametricHenneberg::vtkParametricHenneberg() this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricHenneberg::~vtkParametricHenneberg() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricHenneberg::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -66,16 +66,16 @@ void vtkParametricHenneberg::Evaluate(double uvw[3], double Pt[3], double Duvw[9 Dv[0] = -2.*sinh(u)*sin(v) + 2.*sinh(3.*u)*sin(3.*v); Dv[1] = 2.*sinh(u)*cos(v) + 2.*sinh(3.*u)*cos(3.*v); Dv[2] = -4.*cosh(2.*u)*sin(2.*v); - } +} //----------------------------------------------------------------------------// double vtkParametricHenneberg::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricHenneberg::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricKuen.cxx b/Common/ComputationalGeometry/vtkParametricKuen.cxx index 311267f90cc..b5012ba0563 100644 --- a/Common/ComputationalGeometry/vtkParametricKuen.cxx +++ b/Common/ComputationalGeometry/vtkParametricKuen.cxx @@ -19,7 +19,7 @@ vtkStandardNewMacro(vtkParametricKuen); //----------------------------------------------------------------------------// vtkParametricKuen::vtkParametricKuen() - { +{ // Preset triangulation parameters this->MinimumU = -3.*vtkMath::Pi(); this->MinimumV = 0.; @@ -32,16 +32,16 @@ vtkParametricKuen::vtkParametricKuen() this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricKuen::~vtkParametricKuen() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricKuen::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -71,30 +71,30 @@ void vtkParametricKuen::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) // Avoid division by 0 if (denom_2 == 0.0 || sinv == 0.0) - { + { Du[1] = 0.0; Du[2] = 0.0; - } + } else - { + { Du[1] = (2.*u/sinv*(2.*u*cosu + (u*u - 2. + 1/(sinv*sinv))*sinu))/(denom_2*denom_2); Du[2] = -4.*u*cosv/(denom_2*denom_2*sinv*sinv); - } + } // The derivative with respect to v: Dv[0] = 2.*cosv*(1. - u*u*sinv*sinv)*(cosu + u*sinu)/(denom_1*denom_1); Dv[1] = 2.*cosv*(u*u*sinv*sinv - 1.)*(u*cosu - sinu)/(denom_1*denom_1); Dv[2] = 1./sinv - (2. + u*u*(3. + cos(2*u)))*sinv/(denom_1*denom_1); - } +} //----------------------------------------------------------------------------// double vtkParametricKuen::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricKuen::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricPluckerConoid.cxx b/Common/ComputationalGeometry/vtkParametricPluckerConoid.cxx index 240cb821702..3674a4c9040 100644 --- a/Common/ComputationalGeometry/vtkParametricPluckerConoid.cxx +++ b/Common/ComputationalGeometry/vtkParametricPluckerConoid.cxx @@ -20,7 +20,7 @@ vtkStandardNewMacro(vtkParametricPluckerConoid); //----------------------------------------------------------------------------// vtkParametricPluckerConoid::vtkParametricPluckerConoid() : N(2) - { +{ // Preset triangulation parameters this->MinimumU = 0.; this->MinimumV = 0.; @@ -33,16 +33,16 @@ vtkParametricPluckerConoid::vtkParametricPluckerConoid() : this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricPluckerConoid::~vtkParametricPluckerConoid() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricPluckerConoid::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -67,16 +67,16 @@ void vtkParametricPluckerConoid::Evaluate(double uvw[3], double Pt[3], double Du Dv[0] = -u*sin(v); Dv[1] = u*cos(v); Dv[2] = this->N * cos(this->N * v); - } +} //----------------------------------------------------------------------------// double vtkParametricPluckerConoid::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricPluckerConoid::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricPseudosphere.cxx b/Common/ComputationalGeometry/vtkParametricPseudosphere.cxx index 11a39e795a4..b1ac418befb 100644 --- a/Common/ComputationalGeometry/vtkParametricPseudosphere.cxx +++ b/Common/ComputationalGeometry/vtkParametricPseudosphere.cxx @@ -19,7 +19,7 @@ vtkStandardNewMacro(vtkParametricPseudosphere); //----------------------------------------------------------------------------// vtkParametricPseudosphere::vtkParametricPseudosphere() - { +{ // Preset triangulation parameters this->MinimumU = -5.0; this->MinimumV = -vtkMath::Pi(); @@ -32,16 +32,16 @@ vtkParametricPseudosphere::vtkParametricPseudosphere() this->TwistV = 0; this->ClockwiseOrdering = 1; this->DerivativesAvailable = 1; - } +} //----------------------------------------------------------------------------// vtkParametricPseudosphere::~vtkParametricPseudosphere() - { - } +{ +} //----------------------------------------------------------------------------// void vtkParametricPseudosphere::Evaluate(double uvw[3], double Pt[3], double Duvw[9]) - { +{ // Copy the parameters out of the vector, for the sake of convenience. double u = uvw[0]; double v = uvw[1]; @@ -73,16 +73,16 @@ void vtkParametricPseudosphere::Evaluate(double uvw[3], double Pt[3], double Duv Dv[0] = -sechu*sinv; Dv[1] = sechu*cosv; Dv[2] = 0.; - } +} //----------------------------------------------------------------------------// double vtkParametricPseudosphere::EvaluateScalar(double *, double *, double *) - { +{ return 0; - } +} //----------------------------------------------------------------------------// void vtkParametricPseudosphere::PrintSelf(ostream& os, vtkIndent indent) - { +{ this->Superclass::PrintSelf(os,indent); - } +} diff --git a/Common/ComputationalGeometry/vtkParametricRandomHills.cxx b/Common/ComputationalGeometry/vtkParametricRandomHills.cxx index 60cadd65448..00737094438 100644 --- a/Common/ComputationalGeometry/vtkParametricRandomHills.cxx +++ b/Common/ComputationalGeometry/vtkParametricRandomHills.cxx @@ -92,9 +92,9 @@ void vtkParametricRandomHills::Evaluate(double uvw[3], double Pt[3], double Duvw { // If parameters have changed then regenerate the hills. if (this->ParametersChanged()) - { + { this->MakeTheHillData(); - } + } double u = uvw[0]; double v = uvw[1]; @@ -111,13 +111,13 @@ void vtkParametricRandomHills::Evaluate(double uvw[3], double Pt[3], double Duvw Pt[0] = u; Pt[1] = this->MaximumV - v; // Texturing is oriented OK if we do this. for ( int j = 0; j < NumberOfHills; ++j ) - { + { double hillTuple[5]; // 0: mX, 1: mY, 2: VarX, 3: VarY, 4: Amplitude this->hillData->GetTuple(j,hillTuple); double x = (u - hillTuple[0])/hillTuple[2]; double y = (v - hillTuple[1])/hillTuple[3]; Pt[2] += hillTuple[4] * exp( -(x*x+y*y) / 2.0 ); - } + } } //---------------------------------------------------------------------------- @@ -139,10 +139,10 @@ void vtkParametricRandomHills::MakeTheHillData( void ) double hillTuple[5]; // 0: mX, 1: mY, 2: VarX, 3: VarY, 4: Amplitude // Generate the centers of the Hills, standard deviations and amplitudes. if ( AllowRandomGeneration != 0 ) - { + { InitRNG(this->RandomSeed); for (int i = 0; i < this->NumberOfHills; ++i) - { + { hillTuple[0] = MinimumU + Rand() * dU; hillTuple[1] = MinimumV + Rand() * dV; hillTuple[2] = this->HillXVariance * @@ -152,10 +152,10 @@ void vtkParametricRandomHills::MakeTheHillData( void ) hillTuple[4] = this->HillAmplitude * (Rand() + this->AmplitudeScaleFactor); this->hillData->SetTuple(i, hillTuple); - } } + } else - { + { // Here the generation is nonrandom. // We put hills in a regular grid over the whole surface. double gridMax = sqrt(static_cast(this->NumberOfHills)); @@ -170,76 +170,76 @@ void vtkParametricRandomHills::MakeTheHillData( void ) hillTuple[3] = this->HillYVariance * this->YVarianceScaleFactor; hillTuple[4] = this->HillAmplitude * this->AmplitudeScaleFactor; for (int i = 0; i < static_cast(gridMax); ++i) - { + { hillTuple[0] = MinimumU + shiftU + (i / gridMax) * dU; for ( int j = 0; j < static_cast(gridMax); ++j ) - { + { hillTuple[1] = MinimumV + shiftV + (j / gridMax) * dV; this->hillData->SetTuple(counter,hillTuple); ++counter; - } } + } // Zero out the variance and amplitude for the remaining hills. hillTuple[2] = 0; hillTuple[3] = 0; hillTuple[4] = 0; for (int k = counter; k < this->NumberOfHills; ++k) - { + { hillTuple[0] = MinimumU + midU; hillTuple[1] = MinimumV + midV; this->hillData->SetTuple(k,hillTuple); - } } + } } //---------------------------------------------------------------------------- bool vtkParametricRandomHills::ParametersChanged() { if (this->previousNumberOfHills != this->NumberOfHills) - { + { this->CopyParameters(); return true; - } + } if (this->previousHillXVariance != this->HillXVariance) - { + { this->CopyParameters(); return true; - } + } if (this->previousHillYVariance != this->HillYVariance) - { + { this->CopyParameters(); return true; - } + } if (this->previousHillAmplitude != this->HillAmplitude) - { + { this->CopyParameters(); return true; - } + } if (this->previousRandomSeed != this->RandomSeed) - { + { this->CopyParameters(); return true; - } + } if (this->previousXVarianceScaleFactor != this->XVarianceScaleFactor) - { + { this->CopyParameters(); return true; - } + } if (this->previousYVarianceScaleFactor != this->YVarianceScaleFactor) - { + { this->CopyParameters(); return true; - } + } if (this->previousAmplitudeScaleFactor != this->AmplitudeScaleFactor) - { + { this->CopyParameters(); return true; - } + } if (this->previousAllowRandomGeneration != this->AllowRandomGeneration) - { + { this->CopyParameters(); return true; - } + } return false; } diff --git a/Common/ComputationalGeometry/vtkParametricSpline.cxx b/Common/ComputationalGeometry/vtkParametricSpline.cxx index 605a069eb3e..29eea2ae221 100644 --- a/Common/ComputationalGeometry/vtkParametricSpline.cxx +++ b/Common/ComputationalGeometry/vtkParametricSpline.cxx @@ -47,32 +47,32 @@ vtkParametricSpline::vtkParametricSpline() vtkParametricSpline::~vtkParametricSpline() { if (this->Points) - { + { this->Points->Delete(); - } + } if (this->XSpline) - { + { this->XSpline->Delete(); - } + } if (this->YSpline) - { + { this->YSpline->Delete(); - } + } if (this->ZSpline) - { + { this->ZSpline->Delete(); - } + } } //---------------------------------------------------------------------------- void vtkParametricSpline::SetNumberOfPoints(vtkIdType numPts) { if (!this->Points) - { + { vtkPoints* pts = vtkPoints::New(VTK_DOUBLE); this->SetPoints(pts); pts->Delete(); - } + } this->Points->SetNumberOfPoints(numPts); this->Modified(); } @@ -82,82 +82,82 @@ void vtkParametricSpline::SetPoint( vtkIdType index, double x, double y, double z) { if (this->Points) - { + { this->Points->SetPoint(index, x, y, z); this->Modified(); - } + } } //---------------------------------------------------------------------------- void vtkParametricSpline::SetPoints(vtkPoints *pts) { if ( pts != this->Points ) - { + { if ( this->Points != NULL ) - { + { this->Points->Delete(); - } + } this->Points = pts; if ( this->Points != NULL ) - { + { this->Points->Register(this); - } - this->Modified(); } + this->Modified(); + } } //---------------------------------------------------------------------------- void vtkParametricSpline::SetXSpline(vtkSpline *s) { if ( s != this->XSpline ) - { + { if ( this->XSpline != NULL ) - { + { this->XSpline->Delete(); - } + } this->XSpline = s; if ( this->XSpline != NULL ) - { + { this->XSpline->Register(this); - } - this->Modified(); } + this->Modified(); + } } //---------------------------------------------------------------------------- void vtkParametricSpline::SetYSpline(vtkSpline *s) { if ( s != this->YSpline ) - { + { if ( this->YSpline != NULL ) - { + { this->YSpline->Delete(); - } + } this->YSpline = s; if ( this->YSpline != NULL ) - { + { this->YSpline->Register(this); - } - this->Modified(); } + this->Modified(); + } } //---------------------------------------------------------------------------- void vtkParametricSpline::SetZSpline(vtkSpline *s) { if ( s != this->ZSpline ) - { + { if ( this->ZSpline != NULL ) - { + { this->ZSpline->Delete(); - } + } this->ZSpline = s; if ( this->ZSpline != NULL ) - { + { this->ZSpline->Register(this); - } - this->Modified(); } + this->Modified(); + } } @@ -166,28 +166,28 @@ void vtkParametricSpline::Evaluate(double U[3], double Pt[3], double*) { // make sure everything has been set up if ( this->InitializeTime < this->GetMTime () ) - { + { if ( ! this->Initialize() ) - { + { return; - } } + } double t = (U[0] < 0.0 ? 0.0 : (U[0] > 1.0 ? 1.0 : U[0])); if ( this->Closed ) - { + { t *= this->ClosedLength; - } + } else - { + { t *= this->Length; - } + } if (this->Length == 0 && this->Points && this->Points->GetNumberOfPoints() > 0) - { + { this->Points->GetPoint(0, Pt); return; - } + } // Evaluate the spline at the parameter t Pt[0] = this->XSpline->Evaluate(t); @@ -200,12 +200,12 @@ double vtkParametricSpline::EvaluateScalar(double u[3], double*, double *) { // make sure everything has been set up if ( this->InitializeTime < this->GetMTime () ) - { + { if ( ! this->Initialize() ) - { + { return 0.0; - } } + } return u[0]; //simply parametric value } @@ -216,15 +216,15 @@ int vtkParametricSpline::Initialize() { // Check to make sure splines are available if ( !this->XSpline || !this->YSpline || !this->ZSpline ) - { + { vtkErrorMacro("Please specify splines"); return 0; - } + } if ( !this->Points ) - { + { vtkErrorMacro("Please specify points"); return 0; - } + } // Make sure that the splines are consistent with this instance this->XSpline->SetClosed(this->GetClosed()); @@ -251,24 +251,24 @@ int vtkParametricSpline::Initialize() vtkIdType npts = this->Points->GetNumberOfPoints(); if ( npts < 1) - { + { vtkErrorMacro("Please specify at least one point."); return 0; - } + } if ( npts < 2 ) - { + { this->Length = 0; this->ClosedLength = 0; // If number of points == 1, then we simply generate a single point. return 1; - } + } if ( this->ParameterizeByLength ) - { + { this->Points->GetPoint(0,xPrev); this->Length = 0.0; for ( i = 1; i < npts; ++i ) - { + { this->Points->GetPoint(i,x); len = sqrt(vtkMath::Distance2BetweenPoints(x,xPrev)); // No need to complain if there are coincident points, we indeed handle @@ -280,28 +280,28 @@ int vtkParametricSpline::Initialize() // } this->Length += len; xPrev[0]=x[0]; xPrev[1]=x[1]; xPrev[2]=x[2]; - } + } if ( this->Length <= 0.0 ) - { + { // Zero length spline is same a single point. this->ClosedLength = 0.0; return 1; - } + } if ( this->Closed ) - { + { this->Points->GetPoint(0,x); this->ClosedLength = this->Length + sqrt(vtkMath::Distance2BetweenPoints(x,xPrev)); - } } + } else - { + { this->Length = npts - 1; if ( this->Closed ) - { + { this->ClosedLength = npts; - } } + } this->XSpline->RemoveAllPoints(); this->YSpline->RemoveAllPoints(); @@ -309,26 +309,26 @@ int vtkParametricSpline::Initialize() // Specify the parametric range that the spline can take if ( ! this->Closed ) - { + { this->XSpline->SetParametricRange(0.0,this->Length); this->YSpline->SetParametricRange(0.0,this->Length); this->ZSpline->SetParametricRange(0.0,this->Length); - } + } else - { + { this->XSpline->SetParametricRange(0.0,this->ClosedLength); this->YSpline->SetParametricRange(0.0,this->ClosedLength); this->ZSpline->SetParametricRange(0.0,this->ClosedLength); - } + } // Now we insert points into the splines with the parametric coordinate // based on (polyline) length. We keep track of the parametric coordinates // of the points for later point interpolation. if ( this->ParameterizeByLength ) - { + { this->Points->GetPoint(0,xPrev); for ( len = 0.0, i = 0; i < npts; ++i ) - { + { this->Points->GetPoint(i,x); len += sqrt(vtkMath::Distance2BetweenPoints(x,xPrev)); @@ -337,18 +337,18 @@ int vtkParametricSpline::Initialize() this->ZSpline->AddPoint(len,x[2]); xPrev[0]=x[0]; xPrev[1]=x[1]; xPrev[2]=x[2]; - } } + } else - { + { for ( i = 0; i < npts; ++i ) - { + { this->Points->GetPoint(i,x); this->XSpline->AddPoint(i,x[0]); this->YSpline->AddPoint(i,x[1]); this->ZSpline->AddPoint(i,x[2]); - } } + } this->InitializeTime = this->GetMTime(); return 1; @@ -362,41 +362,41 @@ void vtkParametricSpline::PrintSelf(ostream& os, vtkIndent indent) os << indent << "Points: "; if ( this->Points ) - { + { os << this->Points << "\n"; - } + } else - { + { os << "(none)\n"; - } + } os << indent << "X Spline: "; if ( this->XSpline ) - { + { os << this->XSpline << "\n"; - } + } else - { + { os << "(none)\n"; - } + } os << indent << "Y Spline: "; if ( this->YSpline ) - { + { os << this->YSpline << "\n"; - } + } else - { + { os << "(none)\n"; - } + } os << indent << "Z Spline: "; if ( this->ZSpline ) - { + { os << this->ZSpline << "\n"; - } + } else - { + { os << "(none)\n"; - } + } os << indent << "Closed: " << (this->Closed ? "On\n" : "Off\n"); os << indent << "Left Constraint: " << this->LeftConstraint << "\n"; diff --git a/Common/ComputationalGeometry/vtkParametricSuperEllipsoid.cxx b/Common/ComputationalGeometry/vtkParametricSuperEllipsoid.cxx index 67060efd695..c42e67744b5 100644 --- a/Common/ComputationalGeometry/vtkParametricSuperEllipsoid.cxx +++ b/Common/ComputationalGeometry/vtkParametricSuperEllipsoid.cxx @@ -54,9 +54,9 @@ void vtkParametricSuperEllipsoid::Evaluate(double uvw[3], double Pt[3], double D double *Dv = Duvw + 3; for ( int i = 0; i < 3; ++i) - { + { Pt[i] = Du[i] = Dv[i] = 0; - } + } double cu = cos(u); double su = sin(u); @@ -93,15 +93,15 @@ void vtkParametricSuperEllipsoid::PrintSelf(ostream& os, vtkIndent indent) double vtkParametricSuperEllipsoid::Power ( double x, double n ) { if ( x == 0 ) - { + { return 0; - } + } else if ( x < 0 ) - { + { return -pow(-x,n); - } + } else - { + { return pow(x,n); - } + } } diff --git a/Common/ComputationalGeometry/vtkParametricSuperToroid.cxx b/Common/ComputationalGeometry/vtkParametricSuperToroid.cxx index 4ff8e13ee3e..845de53d90d 100644 --- a/Common/ComputationalGeometry/vtkParametricSuperToroid.cxx +++ b/Common/ComputationalGeometry/vtkParametricSuperToroid.cxx @@ -58,9 +58,9 @@ void vtkParametricSuperToroid::Evaluate(double uvw[3], double Pt[3], double Duvw double *Dv = Duvw + 3; for ( int i = 0; i < 3; ++i) - { + { Pt[i] = Du[i] = Dv[i] = 0; - } + } double cu = cos(u); double su = sin(u); @@ -100,15 +100,15 @@ void vtkParametricSuperToroid::PrintSelf(ostream& os, vtkIndent indent) double vtkParametricSuperToroid::Power ( double x, double n ) { if ( x == 0 ) - { + { return 0; - } + } if ( x < 0 ) - { + { return -pow(-x,n); - } + } else - { + { return pow(x,n); - } + } } diff --git a/Common/Core/SMP/OpenMP/vtkSMPThreadLocal.h.in b/Common/Core/SMP/OpenMP/vtkSMPThreadLocal.h.in index 1da9a5a5c62..f650351ef8f 100644 --- a/Common/Core/SMP/OpenMP/vtkSMPThreadLocal.h.in +++ b/Common/Core/SMP/OpenMP/vtkSMPThreadLocal.h.in @@ -61,9 +61,9 @@ public: detail::ThreadSpecificStorageIterator it; it.SetThreadSpecificStorage(Backend); for (it.SetToBegin(); !it.GetAtEnd(); it.Forward()) - { + { delete reinterpret_cast(it.GetStorage()); - } + } } // Description: @@ -79,9 +79,9 @@ public: detail::StoragePointerType &ptr = this->Backend.GetStorage(); T *local = reinterpret_cast(ptr); if (!ptr) - { + { ptr = local = new T(this->Exemplar); - } + } return *local; } diff --git a/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.cxx b/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.cxx index fb5716c7130..8c0962f8d66 100644 --- a/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.cxx +++ b/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.cxx @@ -40,10 +40,10 @@ inline HashType GetHash(ThreadIdType id) unsigned char *be = bp + sizeof(id); HashType hval = offset_basis; while (bp < be) - { + { hval ^= static_cast(*bp++); hval *= FNV_prime; - } + } return hval; } @@ -55,14 +55,14 @@ class LockGuard LockGuard(omp_lock_t &lock, bool wait) : Lock(lock), Status(0) { if (wait) - { + { omp_set_lock(&this->Lock); this->Status = 1; - } + } else - { + { this->Status = omp_test_lock(&this->Lock); - } + } } bool Success() const @@ -73,10 +73,10 @@ class LockGuard void Release() { if (this->Status) - { + { omp_unset_lock(&this->Lock); this->Status = 0; - } + } } ~LockGuard() @@ -123,9 +123,9 @@ static Slot* LookupSlot(HashTableArray *array, ThreadIdType threadId, size_t hash) { if (!array) - { + { return NULL; - } + } size_t mask = array->Size - 1u; Slot *slot = NULL; @@ -133,19 +133,19 @@ static Slot* LookupSlot(HashTableArray *array, ThreadIdType threadId, // since load factor is maintained bellow 0.5, this loop should hit an // empty slot if the queried slot does not exist in this array for (size_t idx = hash & mask; ; idx = (idx + 1) & mask) // linear probing - { + { slot = array->Slots + idx; ThreadIdType slotThreadId = slot->ThreadId.load(); // atomic read if (!slotThreadId) // empty slot means threadId doesn't exist in this array - { + { slot = LookupSlot(array->Prev, threadId, hash); break; - } + } else if (slotThreadId == threadId) - { + { break; - } } + } return slot; } @@ -161,29 +161,29 @@ static Slot* AcquireSlot(HashTableArray *array, ThreadIdType threadId, firstAccess = false; for (size_t idx = hash & mask; ; idx = (idx + 1) & mask) - { + { slot = array->Slots + idx; ThreadIdType slotThreadId = slot->ThreadId.load(); // atomic read if (!slotThreadId) // unused? - { + { // empty slot means threadId does not exist, try to acquire the slot LockGuard lguard(slot->ModifyLock, false); // try to get exclusive access if (lguard.Success()) - { + { size_t size = ++array->NumberOfEntries; // atomic if ((size * 2) > array->Size) // load factor is above threshold - { + { --array->NumberOfEntries; // atomic revert return NULL; // indicate need for resizing - } + } if (!slot->ThreadId.load()) // not acquired in the meantime? - { + { slot->ThreadId.store(threadId); // atomically acquire // check previous arrays for the entry Slot *prevSlot = LookupSlot(array->Prev, threadId, hash); if (prevSlot) - { + { slot->Storage = prevSlot->Storage; // Do not clear PrevSlot's ThreadId as our technique of stopping // linear probing at empty slots relies on slots not being @@ -192,21 +192,21 @@ static Slot* AcquireSlot(HashTableArray *array, ThreadIdType threadId, // ensure that it doesn't iterate over the same thread's storage // more than once. prevSlot->Storage = NULL; - } + } else // first time access - { + { slot->Storage = NULL; firstAccess = true; - } - break; } + break; } } + } else if (slotThreadId == threadId) - { + { break; - } } + } return slot; } @@ -218,13 +218,13 @@ ThreadSpecific::ThreadSpecific(unsigned numThreads) // lastSetBit = floor(log2(numThreads)) int lastSetBit = 0; for (int i = (sizeof(unsigned) * 8) - 1; i >= 0; --i) - { + { if (numThreads & (1u << i)) - { + { lastSetBit = i; break; - } } + } // initial size should be more than twice the number of threads size_t initSizeLg = (lastSetBit + 2); @@ -235,11 +235,11 @@ ThreadSpecific::~ThreadSpecific() { HashTableArray *array = this->Root; while (array) - { + { HashTableArray *tofree = array; array = array->Prev; delete tofree; - } + } } StoragePointerType& ThreadSpecific::GetStorage() @@ -249,25 +249,25 @@ StoragePointerType& ThreadSpecific::GetStorage() Slot *slot = NULL; while (!slot) - { + { bool firstAccess = false; HashTableArray *array = this->Root.load(); slot = AcquireSlot(array, threadId, hash, firstAccess); if (!slot) // not enough room, resize - { + { # pragma omp critical (HashTableResize) if (this->Root == array) - { + { HashTableArray *newArray = new HashTableArray(array->SizeLg + 1); newArray->Prev = array; this->Root.store(newArray); // atomic copy - } } + } else if (firstAccess) - { + { ++this->Count; // atomic increment - } } + } return slot->Storage; } diff --git a/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.h.in b/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.h.in index d018785104e..5096a403aa5 100644 --- a/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.h.in +++ b/Common/Core/SMP/OpenMP/vtkSMPThreadLocalImpl.h.in @@ -121,9 +121,9 @@ public: this->CurrentArray = this->ThreadSpecificStorage->Root; this->CurrentSlot = 0; if (!this->CurrentArray->Slots->Storage) - { + { this->Forward(); - } + } } void SetToEnd() @@ -145,22 +145,22 @@ public: void Forward() { for (;;) - { + { if (++this->CurrentSlot >= this->CurrentArray->Size) - { + { this->CurrentArray = this->CurrentArray->Prev; this->CurrentSlot = 0; if (!this->CurrentArray) - { + { break; - } } + } Slot *slot = this->CurrentArray->Slots + this->CurrentSlot; if (slot->Storage) - { + { break; - } } + } } StoragePointerType& GetStorage() const diff --git a/Common/Core/SMP/OpenMP/vtkSMPTools.cxx b/Common/Core/SMP/OpenMP/vtkSMPTools.cxx index f5b0992ab8e..97557ebc868 100644 --- a/Common/Core/SMP/OpenMP/vtkSMPTools.cxx +++ b/Common/Core/SMP/OpenMP/vtkSMPTools.cxx @@ -28,10 +28,10 @@ void vtkSMPTools::Initialize(int numThreads) { # pragma omp single if (numThreads) - { + { vtkSMPNumberOfSpecifiedThreads = numThreads; omp_set_num_threads(numThreads); - } + } } int vtkSMPTools::GetEstimatedNumberOfThreads() @@ -50,14 +50,14 @@ void vtk::detail::smp::vtkSMPTools_Impl_For_OpenMP(vtkIdType first, void *functor) { if (grain <= 0) - { + { vtkIdType estimateGrain = (last - first)/(omp_get_max_threads() * 4); grain = (estimateGrain > 0) ? estimateGrain : 1; - } + } # pragma omp parallel for schedule(runtime) for (vtkIdType from = first; from < last; from += grain) - { + { functorExecuter(functor, from, grain, last); - } + } } diff --git a/Common/Core/SMP/OpenMP/vtkSMPToolsInternal.h.in b/Common/Core/SMP/OpenMP/vtkSMPToolsInternal.h.in index 1ad936f5b37..a683748bab3 100644 --- a/Common/Core/SMP/OpenMP/vtkSMPToolsInternal.h.in +++ b/Common/Core/SMP/OpenMP/vtkSMPToolsInternal.h.in @@ -42,9 +42,9 @@ void ExecuteFunctor(void *functor, vtkIdType from, vtkIdType grain, { vtkIdType to = from + grain; if (to > last) - { + { to = last; - } + } FunctorInternal &fi = *reinterpret_cast(functor); fi.Execute(from, to); @@ -56,19 +56,19 @@ static void vtkSMPTools_Impl_For(vtkIdType first, vtkIdType last, { vtkIdType n = last - first; if (n <= 0) - { + { return; - } + } if (grain >= n) - { + { fi.Execute(first, last); - } + } else - { + { vtkSMPTools_Impl_For_OpenMP(first, last, grain, ExecuteFunctor, &fi); - } + } } //-------------------------------------------------------------------------------- diff --git a/Common/Core/SMP/Sequential/vtkAtomic.cxx b/Common/Core/SMP/Sequential/vtkAtomic.cxx index 8f50ed725a0..95c7d2e69d1 100644 --- a/Common/Core/SMP/Sequential/vtkAtomic.cxx +++ b/Common/Core/SMP/Sequential/vtkAtomic.cxx @@ -36,7 +36,7 @@ #include "vtkSimpleCriticalSection.h" class CriticalSectionGuard -{ + { public: CriticalSectionGuard(vtkSimpleCriticalSection &cs) : CriticalSection(cs) { @@ -54,7 +54,7 @@ class CriticalSectionGuard void operator=(const CriticalSectionGuard&); vtkSimpleCriticalSection &CriticalSection; -}; + }; #if defined(VTK_LOCK_BASED_ATOMICS_64) detail::AtomicOps<8>::atomic_type::atomic_type(vtkTypeInt64 init) diff --git a/Common/Core/SMP/Sequential/vtkSMPThreadLocal.h.in b/Common/Core/SMP/Sequential/vtkSMPThreadLocal.h.in index bf8dd9b09c2..60041a3f421 100644 --- a/Common/Core/SMP/Sequential/vtkSMPThreadLocal.h.in +++ b/Common/Core/SMP/Sequential/vtkSMPThreadLocal.h.in @@ -49,9 +49,9 @@ public: // Description: // Default constructor. Creates a default exemplar. vtkSMPThreadLocal() : NumInitialized(0) - { + { this->Initialize(); - } + } // Description: // Constructor that allows the specification of an exemplar object @@ -59,9 +59,9 @@ public: // Note that a copy of the exemplar is created using its copy constructor. explicit vtkSMPThreadLocal(const T& exemplar) : NumInitialized(0), Exemplar(exemplar) - { + { this->Initialize(); - } + } // Description: // Returns an object of type T that is local to the current thread. @@ -72,23 +72,23 @@ public: // the first time it is called. After the first time, it will return // the same object. T& Local() - { + { int tid = this->GetThreadID(); if (!this->Initialized[tid]) - { + { this->Internal[tid] = this->Exemplar; this->Initialized[tid] = true; ++this->NumInitialized; - } + } return this->Internal[tid]; - } + } // Description: // Return the number of thread local objects that have been initialized size_t size() const - { + { return this->NumInitialized; - } + } // Description: // Subset of the standard iterator API. @@ -102,50 +102,50 @@ public: { public: iterator& operator++() - { + { this->InitIter++; this->Iter++; // Make sure to skip uninitialized // entries. while(this->InitIter != this->EndIter) - { + { if (*this->InitIter) - { + { break; - } + } this->InitIter++; this->Iter++; - } + } return *this; - } + } iterator operator++(int) - { + { iterator copy = *this; ++(*this); return copy; - } + } bool operator==(const iterator& other) - { + { return this->Iter == other.Iter; - } + } bool operator!=(const iterator& other) - { + { return this->Iter != other.Iter; - } + } T& operator*() - { + { return *this->Iter; - } + } T* operator->() - { + { return &*this->Iter; - } + } private: friend class vtkSMPThreadLocal; @@ -158,7 +158,7 @@ public: // Returns a new iterator pointing to the beginning of // the local storage container. Thread safe. iterator begin() - { + { TLSIter iter = this->Internal.begin(); std::vector::iterator iter2 = this->Initialized.begin(); @@ -167,32 +167,32 @@ public: // fast forward to first initialized // value while(iter2 != enditer) - { + { if (*iter2) - { + { break; - } + } iter2++; iter++; - } + } iterator retVal; retVal.InitIter = iter2; retVal.EndIter = enditer; retVal.Iter = iter; return retVal; - }; + }; // Description: // Returns a new iterator pointing to past the end of // the local storage container. Thread safe. iterator end() - { + { iterator retVal; retVal.InitIter = this->Initialized.end(); retVal.EndIter = this->Initialized.end(); retVal.Iter = this->Internal.end(); return retVal; - } + } private: TLS Internal; @@ -201,23 +201,23 @@ private: T Exemplar; void Initialize() - { + { this->Internal.resize(this->GetNumberOfThreads()); this->Initialized.resize(this->GetNumberOfThreads()); std::fill(this->Initialized.begin(), this->Initialized.end(), false); - } + } inline int GetNumberOfThreads() - { + { return 1; - } + } inline int GetThreadID() - { + { return 0; - } + } // disable copying vtkSMPThreadLocal(const vtkSMPThreadLocal&); diff --git a/Common/Core/SMP/Sequential/vtkSMPToolsInternal.h.in b/Common/Core/SMP/Sequential/vtkSMPToolsInternal.h.in index c0e95e3b3d2..67111c7e357 100644 --- a/Common/Core/SMP/Sequential/vtkSMPToolsInternal.h.in +++ b/Common/Core/SMP/Sequential/vtkSMPToolsInternal.h.in @@ -27,28 +27,28 @@ static void vtkSMPTools_Impl_For( { vtkIdType n = last - first; if (!n) - { + { return; - } + } if (grain == 0 || grain >= n) - { + { fi.Execute(first, last); - } + } else - { + { vtkIdType b = first; while (b < last) - { + { vtkIdType e = b + grain; if (e > last) - { + { e = last; - } + } fi.Execute(b, e); b = e; - } } + } } //-------------------------------------------------------------------------------- diff --git a/Common/Core/SMP/TBB/vtkSMPThreadLocal.h.in b/Common/Core/SMP/TBB/vtkSMPThreadLocal.h.in index c141983fbff..f0ed27ad744 100644 --- a/Common/Core/SMP/TBB/vtkSMPThreadLocal.h.in +++ b/Common/Core/SMP/TBB/vtkSMPThreadLocal.h.in @@ -91,16 +91,16 @@ public: // Description: // Default constructor. Creates a default exemplar. vtkSMPThreadLocal() - { - } + { + } // Description: // Constructor that allows the specification of an exemplar object // which is used when constructing objects when Local() is first called. // Note that a copy of the exemplar is created using its copy constructor. explicit vtkSMPThreadLocal(const T& exemplar) : Internal(exemplar) - { - } + { + } // Description: // Returns an object of type T that is local to the current thread. @@ -111,16 +111,16 @@ public: // the first time it is called. After the first time, it will return // the same object. T& Local() - { + { return this->Internal.local(); - } + } // Description: // Return the number of thread local objects that have been initialized size_t size() const - { + { return this->Internal.size(); - } + } // Description: // Subset of the standard iterator API. @@ -134,37 +134,37 @@ public: { public: iterator& operator++() - { + { ++this->Iter; return *this; - } + } iterator operator++(int) - { + { iterator copy = *this; ++this->Iter; return copy; - } + } bool operator==(const iterator& other) - { + { return this->Iter == other.Iter; - } + } bool operator!=(const iterator& other) - { + { return this->Iter != other.Iter; - } + } T& operator*() - { + { return *this->Iter; - } + } T* operator->() - { + { return &*this->Iter; - } + } private: TLSIter Iter; @@ -176,21 +176,21 @@ public: // Returns a new iterator pointing to the beginning of // the local storage container. Thread safe. iterator begin() - { + { iterator iter; iter.Iter = this->Internal.begin(); return iter; - }; + }; // Description: // Returns a new iterator pointing to past the end of // the local storage container. Thread safe. iterator end() - { + { iterator iter; iter.Iter = this->Internal.end(); return iter; - } + } private: TLS Internal; diff --git a/Common/Core/SMP/TBB/vtkSMPTools.cxx b/Common/Core/SMP/TBB/vtkSMPTools.cxx index 67040f1be22..ee3eab467f8 100644 --- a/Common/Core/SMP/TBB/vtkSMPTools.cxx +++ b/Common/Core/SMP/TBB/vtkSMPTools.cxx @@ -24,8 +24,8 @@ struct vtkSMPToolsInit tbb::task_scheduler_init Init; vtkSMPToolsInit(int numThreads) : Init(numThreads) - { - } + { + } }; static bool vtkSMPToolsInitialized = 0; @@ -37,16 +37,16 @@ void vtkSMPTools::Initialize(int numThreads) { vtkSMPToolsCS.Lock(); if (!vtkSMPToolsInitialized) - { + { // If numThreads <= 0, don't create a task_scheduler_init // and let TBB do the default thing. if (numThreads > 0) - { + { static vtkSMPToolsInit aInit(numThreads); vtkTBBNumSpecifiedThreads = numThreads; - } - vtkSMPToolsInitialized = true; } + vtkSMPToolsInitialized = true; + } vtkSMPToolsCS.Unlock(); } diff --git a/Common/Core/SMP/TBB/vtkSMPToolsInternal.h.in b/Common/Core/SMP/TBB/vtkSMPToolsInternal.h.in index 5d9657dfcc6..622e707c4c5 100644 --- a/Common/Core/SMP/TBB/vtkSMPToolsInternal.h.in +++ b/Common/Core/SMP/TBB/vtkSMPToolsInternal.h.in @@ -36,13 +36,13 @@ class FuncCall public: void operator() (const tbb::blocked_range& r) const - { + { o.Execute(r.begin(), r.end()); - } + } FuncCall (T& _o) : o(_o) - { - } + { + } }; //-------------------------------------------------------------------------------- @@ -53,17 +53,17 @@ static void vtkSMPTools_Impl_For( { vtkIdType n = last - first; if (!n) - { + { return; - } + } if (grain > 0) - { + { tbb::parallel_for(tbb::blocked_range(first, last, grain), FuncCall(fi)); - } + } else - { + { tbb::parallel_for(tbb::blocked_range(first, last), FuncCall(fi)); - } + } } //-------------------------------------------------------------------------------- diff --git a/Common/Core/Testing/Cxx/TestAngularPeriodicDataArray.cxx b/Common/Core/Testing/Cxx/TestAngularPeriodicDataArray.cxx index 706f281bd27..148cd5b47c7 100644 --- a/Common/Core/Testing/Cxx/TestAngularPeriodicDataArray.cxx +++ b/Common/Core/Testing/Cxx/TestAngularPeriodicDataArray.cxx @@ -65,7 +65,7 @@ int TestAngularPeriodicDataArray(int, char * []) std::abs(range[2] - 9.1344434349507945825) >= dEpsilon || std::abs(range[4] - 8.29182990260197883) >= dEpsilon ) - { + { cerr.precision(20); cerr << "Error in vtkAngularPeriodicDataArray : " << endl << "Double Array : " << endl << std::abs(pTmp[0] - 7.77777777777) << " " @@ -78,7 +78,7 @@ int TestAngularPeriodicDataArray(int, char * []) << std::abs(range[4] - 8.29182990260198) << endl << "Epsilon : " << fEpsilon << " " << dEpsilon << endl; return 1; - } + } tmp[0] = 1.; @@ -91,13 +91,13 @@ int TestAngularPeriodicDataArray(int, char * []) std::abs(pTmp2[1] - 12.3) >= fEpsilon || std::abs(pTmp2[2] - -4.6191568) >= fEpsilon ) - { + { cerr << "Error in vtkAngularPeriodicDataArray : " << endl << "Non Zero origin rotation : " << endl << std::abs(pTmp2[0] - 4.7902297) << " " << std::abs(pTmp2[1] - 12.3) << " " << std::abs(pTmp2[2] - -4.6191568) << endl; return 1; - } + } vtkNew tensorArray; vtkNew > tensorPArray; @@ -132,7 +132,7 @@ int TestAngularPeriodicDataArray(int, char * []) std::abs(pTmp3[6] - 3417.4749403678183626) >= dEpsilon || std::abs(pTmp3[7] - 2136.7724473977045818) >= dEpsilon || std::abs(pTmp3[8] - 19.19191919) >= dEpsilon) - { + { cerr.precision(20); cerr << "Error while rotating tensor : " << std::abs(pTmp3[0] - 2.0096597239047708783) << " " << std::abs(pTmp3[1] - 13.555918489185591724) << " " << @@ -143,6 +143,6 @@ int TestAngularPeriodicDataArray(int, char * []) std::abs(pTmp3[6] - 3417.4749403678183626) << " " << std::abs(pTmp3[7] - 2136.7724473977045818) << " " << std::abs(pTmp3[8] - 19.19191919) << " " << dEpsilon << endl; - } + } return 0; } diff --git a/Common/Core/Testing/Cxx/TestArrayAPI.cxx b/Common/Core/Testing/Cxx/TestArrayAPI.cxx index ccb14d6c414..937fb3d6337 100644 --- a/Common/Core/Testing/Cxx/TestArrayAPI.cxx +++ b/Common/Core/Testing/Cxx/TestArrayAPI.cxx @@ -30,17 +30,17 @@ #define test_expression(expression) \ { \ if(!(expression)) \ - { \ + { \ std::ostringstream buffer; \ buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \ throw std::runtime_error(buffer.str()); \ - } \ + } \ } int TestArrayAPI(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { try - { + { vtkSmartPointer array; // Test to see that we can create every supported combination of storage- and value-type. @@ -77,9 +77,9 @@ int TestArrayAPI(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) sample_values.push_back(vtkVariant(12.0)); for(std::vector::const_iterator storage_type = storage_types.begin(); storage_type != storage_types.end(); ++storage_type) - { + { for(size_t value_type = 0; value_type != value_types.size(); ++value_type) - { + { cerr << "creating array with storage type " << *storage_type << " and value type " << vtkImageScalarTypeNameMacro(value_types[value_type]) << endl; array.TakeReference(vtkArray::CreateArray(*storage_type, value_types[value_type])); @@ -93,8 +93,8 @@ int TestArrayAPI(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) array->SetVariantValue(5, sample_values[value_type]); test_expression(array->GetVariantValue(5).IsValid()); test_expression(array->GetVariantValue(5) == sample_values[value_type]); - } } + } // Do some spot-checking to see that the actual type matches what we expect ... array.TakeReference(vtkArray::CreateArray(vtkArray::DENSE, VTK_DOUBLE)); @@ -104,10 +104,10 @@ int TestArrayAPI(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) test_expression(vtkSparseArray::SafeDownCast(array)); return 0; - } + } catch(std::exception& e) - { + { cerr << e.what() << endl; return 1; - } + } } diff --git a/Common/Core/Testing/Cxx/TestArrayAPIConvenience.cxx b/Common/Core/Testing/Cxx/TestArrayAPIConvenience.cxx index 4f4d24393fd..4d1fd51862b 100644 --- a/Common/Core/Testing/Cxx/TestArrayAPIConvenience.cxx +++ b/Common/Core/Testing/Cxx/TestArrayAPIConvenience.cxx @@ -29,17 +29,17 @@ #define test_expression(expression) \ { \ if(!(expression)) \ - { \ + { \ std::ostringstream buffer; \ buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \ throw std::runtime_error(buffer.str()); \ - } \ + } \ } int TestArrayAPIConvenience(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { try - { + { vtkSmartPointer > a = vtkSmartPointer >::New(); vtkSmartPointer > b = vtkSmartPointer >::New(); @@ -68,10 +68,10 @@ int TestArrayAPIConvenience(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) test_expression(a->GetValue(2, 3, 4) == b->GetValue(vtkArrayCoordinates(2, 3, 4))); return 0; - } + } catch(std::exception& e) - { + { cerr << e.what() << endl; return 1; - } + } } diff --git a/Common/Core/Testing/Cxx/TestArrayAPIDense.cxx b/Common/Core/Testing/Cxx/TestArrayAPIDense.cxx index cb92728f0ea..9017e3c436b 100644 --- a/Common/Core/Testing/Cxx/TestArrayAPIDense.cxx +++ b/Common/Core/Testing/Cxx/TestArrayAPIDense.cxx @@ -29,17 +29,17 @@ #define test_expression(expression) \ { \ if(!(expression)) \ - { \ + { \ std::ostringstream buffer; \ buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \ throw std::runtime_error(buffer.str()); \ - } \ + } \ } int TestArrayAPIDense(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { try - { + { // Create an array ... vtkSmartPointer > array = vtkSmartPointer >::New(); array->Resize(vtkArrayExtents::Uniform(3, 0)); @@ -71,43 +71,43 @@ int TestArrayAPIDense(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) array->Fill(0.0); const vtkArrayExtents extents = array->GetExtents(); for(vtkIdType i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(vtkIdType j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(vtkIdType k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == 0.0); - } } } } + } // Verify that we can write data into the array and read it out again ... { double value = 0; const vtkArrayExtents extents = array->GetExtents(); for(vtkIdType i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(vtkIdType j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(vtkIdType k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { array->SetValue(vtkArrayCoordinates(i, j, k), value++); - } } } } + } { double value = 0; vtkIdType index = 0; const vtkArrayExtents extents = array->GetExtents(); for(vtkIdType i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(vtkIdType j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(vtkIdType k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == value); vtkArrayCoordinates coordinates; @@ -115,10 +115,10 @@ int TestArrayAPIDense(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) ++index; ++value; - } } } } + } // Verify that fill works correctly ... array->Fill(19700827); @@ -158,10 +158,10 @@ int TestArrayAPIDense(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) test_expression(array->GetValue(1, 0) == 6); return 0; - } + } catch(std::exception& e) - { + { cerr << e.what() << endl; return 1; - } + } } diff --git a/Common/Core/Testing/Cxx/TestArrayAPISparse.cxx b/Common/Core/Testing/Cxx/TestArrayAPISparse.cxx index 8b027a9e87d..e3d4b07807e 100644 --- a/Common/Core/Testing/Cxx/TestArrayAPISparse.cxx +++ b/Common/Core/Testing/Cxx/TestArrayAPISparse.cxx @@ -38,7 +38,7 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { try - { + { // Create an 3D array ... vtkSmartPointer > array = vtkSmartPointer >::New(); array->Resize(vtkArrayExtents::Uniform(3, 0)); @@ -70,43 +70,43 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { const vtkArrayExtents extents = array->GetExtents(); for(int i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(int j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(int k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == 0); - } } } } + } // Verify that we can write data into the array with AddValue() and read it out again ... { double value = 0; const vtkArrayExtents extents = array->GetExtents(); for(int i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(int j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(int k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { array->AddValue(vtkArrayCoordinates(i, j, k), value++); - } } } } + } { double value = 0; vtkIdType index = 0; const vtkArrayExtents extents = array->GetExtents(); for(int i = extents[0].GetBegin(); i != extents[0].GetEnd(); ++i) - { + { for(int j = extents[1].GetBegin(); j != extents[1].GetEnd(); ++j) - { + { for(int k = extents[2].GetBegin(); k != extents[2].GetEnd(); ++k) - { + { test_expression(array->GetValue(i, j, k) == value); test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == value); test_expression(array->GetValueN(index) == value); @@ -120,10 +120,10 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) ++index; ++value; - } } } } + } // Verify the number of non-null values test_expression(array->GetNonNullSize() == 6); @@ -139,9 +139,9 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) test_expression(deep_copy->GetExtents() == array->GetExtents()); test_expression(deep_copy->GetNullValue() == array->GetNullValue()); for(vtkArray::SizeT n = 0; n != deep_copy->GetNonNullSize(); ++n) - { + { test_expression(deep_copy->GetValueN(n) == array->GetValueN(n)); - } + } // Verify that the Clear() method removes all values from the array ... array->Clear(); test_expression(array->GetDimensions() == 3); @@ -190,9 +190,9 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) array->GetCoordinateStorage(0); for (unsigned int i = 0; i < array->GetNonNullSize() - 1; ++i) - { + { test_expression(coords[i] < coords[i+1]); - } + } // ------------------------------------------------------------ // Verify Set/Add/GetValue and SetExtentsFromContents for 0, 1, 2 @@ -412,10 +412,10 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) "NonNullSize:") != std::string::npos); return 0; - } + } catch(std::exception& e) - { + { std::cerr << e.what() << endl; return 1; - } + } } diff --git a/Common/Core/Testing/Cxx/TestArrayBool.cxx b/Common/Core/Testing/Cxx/TestArrayBool.cxx index 19298316a88..dff23b484b7 100644 --- a/Common/Core/Testing/Cxx/TestArrayBool.cxx +++ b/Common/Core/Testing/Cxx/TestArrayBool.cxx @@ -30,17 +30,17 @@ #define test_expression(expression) \ { \ if(!(expression)) \ - { \ + { \ std::ostringstream buffer; \ buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \ throw std::runtime_error(buffer.str()); \ - } \ + } \ } int TestArrayBool(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) { try - { + { // Confirm that we can work with dense arrays of bool values vtkSmartPointer > dense = vtkSmartPointer >::New(); vtkDenseArray& dense_ref = *dense; @@ -66,10 +66,10 @@ int TestArrayBool(int vtkNotUsed(argc), char *vtkNotUsed(argv)[]) test_expression(sparse->GetValue(1, 1) == 1); return 0; - } + } catch(std::exception& e) - { + { cerr << e.what() << endl; return 1; - } + } } diff --git a/Common/Core/Testing/Cxx/TestArrayCasting.cxx b/Common/Core/Testing/Cxx/TestArrayCasting.cxx index 5713ed30e8a..d2d249426a5 100644 --- a/Common/Core/Testing/Cxx/TestArrayCasting.cxx +++ b/Common/Core/Testing/Cxx/TestArrayCasting.cxx @@ -36,11 +36,11 @@ #define test_expression(expression) \ { \ if(!(expression)) \ - { \ + { \ std::ostringstream buffer; \ buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \ throw std::runtime_error(buffer.str()); \ - } \ + } \ } class DowncastTest @@ -68,18 +68,18 @@ void SuccessTest(vtkObject* source, int line) { int count = 0; if(!vtkTryDowncast(source, DowncastTest(count))) - { + { std::ostringstream buffer; buffer << "Expression failed at line " << line; throw std::runtime_error(buffer.str()); - } + } if(count != 1) - { + { std::ostringstream buffer; buffer << "Functor was called " << count << " times at line " << line; throw std::runtime_error(buffer.str()); - } + } } template