Ver código fonte

Use vtkNew instead of deprecated macro VTK_CREATE

* Use of vtkNew is a clean and cpp implementation of
a VTK "scoped" pointer, it avoids to duplicate the macro
VTK_CREATE.

See http://www.vtk.org/doc/nightly/html/classvtkNew.html
Jean-Christophe Fillion-Robin 13 anos atrás
pai
commit
10c367bb9e

+ 18 - 21
Libs/Visualization/VTK/Core/Testing/Cpp/vtkLightBoxRendererManagerTest1.cpp

@@ -25,23 +25,20 @@
 #include "ctkCommandLineParser.h"
 
 // VTK includes
-#include <vtkSmartPointer.h>
-#include <vtkRenderer.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkRenderWindow.h>
-#include <vtkInteractorStyleImage.h>
+#include <vtkImageData.h>
 #include <vtkImageReader2Factory.h>
 #include <vtkImageReader2.h>
-#include <vtkImageData.h>
+#include <vtkInteractorStyleImage.h>
+#include <vtkNew.h>
 #include <vtkRegressionTestImage.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
 #include <vtkTestUtilities.h>
 
 // STD includes
 #include <cstdlib>
-
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
   
 //----------------------------------------------------------------------------
 int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
@@ -52,7 +49,7 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
   // Read Image
   //----------------------------------------------------------------------------
   // Instanciate the reader factory
-  VTK_CREATE(vtkImageReader2Factory, imageFactory);
+  vtkNew<vtkImageReader2Factory> imageFactory;
 
   // Instanciate an image reader
   vtkSmartPointer<vtkImageReader2> imageReader;
@@ -71,19 +68,19 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
   //----------------------------------------------------------------------------
   // Renderer, RenderWindow and Interactor
   //----------------------------------------------------------------------------
-  VTK_CREATE(vtkRenderer, rr);
-  VTK_CREATE(vtkRenderWindow, rw);
-  VTK_CREATE(vtkRenderWindowInteractor, ri);
+  vtkNew<vtkRenderer> rr;
+  vtkNew<vtkRenderWindow> rw;
+  vtkNew<vtkRenderWindowInteractor> ri;
   rw->SetSize(600, 600);
   rw->SetMultiSamples(0); // Ensure to have the same test image everywhere
-  rw->AddRenderer(rr);
-  rw->SetInteractor(ri);
+  rw->AddRenderer(rr.GetPointer());
+  rw->SetInteractor(ri.GetPointer());
   
   // Set Interactor Style
-  VTK_CREATE(vtkInteractorStyleImage, iStyle);
-  ri->SetInteractorStyle(iStyle);
+  vtkNew<vtkInteractorStyleImage> iStyle;
+  ri->SetInteractorStyle(iStyle.GetPointer());
 
-  VTK_CREATE(vtkLightBoxRendererManager, lightBoxRendererManager);
+  vtkNew<vtkLightBoxRendererManager> lightBoxRendererManager;
 
   //----------------------------------------------------------------------------
   // Check if non initialized case is handled properly / Check default value
@@ -190,7 +187,7 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
   // Initialize
   //----------------------------------------------------------------------------
 
-  lightBoxRendererManager->Initialize(rw);
+  lightBoxRendererManager->Initialize(rw.GetPointer());
 
   if (lightBoxRendererManager->IsInitialized() != 1)
     {
@@ -215,7 +212,7 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
   double highlightedBoxColor[3] = {1.0, 1.0, 0.0};
   lightBoxRendererManager->SetHighlightedBoxColor(highlightedBoxColor);
 
-  int retval = vtkRegressionTestImage(rw);
+  int retval = vtkRegressionTestImage(rw.GetPointer());
   if (retval == vtkRegressionTester::DO_INTERACTOR)
     {
     rw->GetInteractor()->Initialize();

+ 23 - 26
Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp

@@ -21,31 +21,28 @@
 #include "vtkLightBoxRendererManager.h"
 
 // VTK includes
-#include <vtkObjectFactory.h>
-#include <vtkSmartPointer.h>
-#include <vtkWeakPointer.h>
-#include <vtkRenderWindow.h>
-#include <vtkRendererCollection.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkTextProperty.h>
-#include <vtkProperty2D.h>
 #include <vtkCamera.h>
+#include <vtkCellArray.h>
+#include <vtkCornerAnnotation.h>
 #include <vtkImageData.h>
 #include <vtkImageMapper.h>
-#include <vtkCellArray.h>
+#include <vtkNew.h>
+#include <vtkObjectFactory.h>
 #include <vtkPoints.h>
 #include <vtkPolyData.h>
 #include <vtkPolyDataMapper2D.h>
-#include <vtkCornerAnnotation.h>
+#include <vtkProperty2D.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
+#include <vtkTextProperty.h>
+#include <vtkWeakPointer.h>
 
 // STD includes
 #include <vector>
 #include <cassert>
 
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
-
 //----------------------------------------------------------------------------
 vtkCxxRevisionMacro(vtkLightBoxRendererManager, "$Revision:$");
 vtkStandardNewMacro(vtkLightBoxRendererManager);
@@ -117,12 +114,12 @@ void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLev
   this->ImageMapper->SetColorLevel(colorLevel);
 
   // .. and its corresponding 2D actor
-  VTK_CREATE(vtkActor2D, actor2D);
+  vtkNew<vtkActor2D> actor2D;
   actor2D->SetMapper(this->ImageMapper);
   actor2D->GetProperty()->SetDisplayLocationToBackground();
 
   // .. and add it to the renderer
-  this->Renderer->AddActor2D(actor2D);
+  this->Renderer->AddActor2D(actor2D.GetPointer());
 }
 
 //---------------------------------------------------------------------------
@@ -132,8 +129,8 @@ void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor
   assert(!this->HighlightedBoxActor);
   
   // Create a highlight actor (2D box around viewport)
-  VTK_CREATE(vtkPolyData, poly);
-  VTK_CREATE(vtkPoints, points);
+  vtkNew<vtkPolyData> poly;
+  vtkNew<vtkPoints> points;
   // Normalized Viewport means :
   // 0. -> 0;
   // 1. -> width - 1 ;
@@ -167,7 +164,7 @@ void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor
   points->InsertNextPoint(0. + shift, 1. + shift, 0); // top-left
   points->InsertNextPoint(0. + shift, 0. + shift - 0.1, 0); // bottom-left to fill the 0,0 pixel.
   
-  VTK_CREATE(vtkCellArray, cells);
+  vtkNew<vtkCellArray> cells;
   cells->InsertNextCell(6);
   cells->InsertCellPoint(0);
   cells->InsertCellPoint(1);
@@ -175,20 +172,20 @@ void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor
   cells->InsertCellPoint(3);
   cells->InsertCellPoint(4);
   cells->InsertCellPoint(5);
-  poly->SetPoints(points);
-  poly->SetLines(cells);
+  poly->SetPoints(points.GetPointer());
+  poly->SetLines(cells.GetPointer());
 
-  VTK_CREATE(vtkCoordinate, coordinate);
+  vtkNew<vtkCoordinate> coordinate;
   coordinate->SetCoordinateSystemToNormalizedViewport();
   coordinate->SetViewport(this->Renderer);
 
-  VTK_CREATE(vtkPolyDataMapper2D, polyDataMapper);
-  polyDataMapper->SetInput(poly);
-  polyDataMapper->SetTransformCoordinate(coordinate);
+  vtkNew<vtkPolyDataMapper2D> polyDataMapper;
+  polyDataMapper->SetInput(poly.GetPointer());
+  polyDataMapper->SetTransformCoordinate(coordinate.GetPointer());
   polyDataMapper->SetTransformCoordinateUseDouble(true);
 
   this->HighlightedBoxActor = vtkSmartPointer<vtkActor2D>::New();
-  this->HighlightedBoxActor->SetMapper(polyDataMapper);
+  this->HighlightedBoxActor->SetMapper(polyDataMapper.GetPointer());
   this->HighlightedBoxActor->GetProperty()->SetColor(highlightedBoxColor[0],
                                                      highlightedBoxColor[1],
                                                      highlightedBoxColor[2]);

+ 15 - 17
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKChartViewTest1.cpp

@@ -27,16 +27,14 @@
 #include "ctkVTKChartView.h"
 
 // VTK includes
-#include "vtkIntArray.h"
-#include <vtkSmartPointer.h>
-#include "vtkTable.h"
+#include <vtkIntArray.h>
+#include <vtkNew.h>
 #include <vtkPlotBar.h>
+#include <vtkTable.h>
 
 // STD includes
 #include <iostream>
 
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
 
 // Monthly circulation data
 static int data_2008[] = {10822, 10941, 9979, 10370, 9460, 11228, 15093, 12231, 10160, 9816, 9384, 7892};
@@ -51,23 +49,23 @@ int ctkVTKChartViewTest1(int argc, char * argv [] )
   ctkVTKChartView view(0);
 
   // Create a table with some points in it...
-  VTK_CREATE(vtkTable, table);
+  vtkNew<vtkTable> table;
 
-  VTK_CREATE(vtkIntArray, arrMonth);
+  vtkNew<vtkIntArray> arrMonth;
   arrMonth->SetName("Month");
-  table->AddColumn(arrMonth);
+  table->AddColumn(arrMonth.GetPointer());
 
-  VTK_CREATE(vtkIntArray, arr2008);
+  vtkNew<vtkIntArray> arr2008;
   arr2008->SetName("2008");
-  table->AddColumn(arr2008);
+  table->AddColumn(arr2008.GetPointer());
 
-  VTK_CREATE(vtkIntArray, arr2009);
+  vtkNew<vtkIntArray> arr2009;
   arr2009->SetName("2009");
-  table->AddColumn(arr2009);
+  table->AddColumn(arr2009.GetPointer());
 
-  VTK_CREATE(vtkIntArray, arr2010);
+  vtkNew<vtkIntArray> arr2010;
   arr2010->SetName("2010");
-  table->AddColumn(arr2010);
+  table->AddColumn(arr2010.GetPointer());
 
   table->SetNumberOfRows(12);
   for (int i = 0; i < 12; i++)
@@ -80,19 +78,19 @@ int ctkVTKChartViewTest1(int argc, char * argv [] )
 
   // Add multiple line plots, setting the colors etc
   vtkPlotBar* bar = vtkPlotBar::New();
-  bar->SetInput(table, 0, 1);
+  bar->SetInput(table.GetPointer(), 0, 1);
   bar->SetColor(0, 255, 0, 255);
   view.addPlot(bar);
   bar->Delete();
 
   bar = vtkPlotBar::New();
-  bar->SetInput(table, 0, 2);
+  bar->SetInput(table.GetPointer(), 0, 2);
   bar->SetColor(255, 0, 0, 255);
   view.addPlot(bar);
   bar->Delete();
 
   bar = vtkPlotBar::New();
-  bar->SetInput(table, 0, 3);
+  bar->SetInput(table.GetPointer(), 0, 3);
   bar->SetColor(0, 0, 255, 255);
   view.addPlot(bar);
   bar->Delete();

+ 6 - 10
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKRenderViewTest1.cpp

@@ -25,9 +25,9 @@
 
 // VTK includes
 #include <vtkActor.h>
+#include <vtkNew.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkRenderer.h>
-#include <vtkSmartPointer.h>
 #include <vtkSphereSource.h>
 
 // CTK includes
@@ -37,10 +37,6 @@
 // STD includes
 #include <iostream>
 
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
-
 //-----------------------------------------------------------------------------
 int ctkVTKRenderViewTest1(int argc, char * argv [] )
 {
@@ -61,17 +57,17 @@ int ctkVTKRenderViewTest1(int argc, char * argv [] )
   renderView.show();
 
   // Instanciate VTK objects
-  VTK_CREATE(vtkSphereSource, sphere);
-  VTK_CREATE(vtkPolyDataMapper, sphereMapper);
-  VTK_CREATE(vtkActor, sphereActor);
+  vtkNew<vtkSphereSource> sphere;
+  vtkNew<vtkPolyDataMapper> sphereMapper;
+  vtkNew<vtkActor> sphereActor;
 
   // Configure actor
   sphere->SetRadius(0.25);
   sphereMapper->SetInputConnection(sphere->GetOutputPort());
-  sphereActor->SetMapper(sphereMapper);
+  sphereActor->SetMapper(sphereMapper.GetPointer());
 
   // Add actor
-  renderView.renderer()->AddActor(sphereActor);
+  renderView.renderer()->AddActor(sphereActor.GetPointer());
 
   renderView.lookFromAxis(ctkAxesWidget::Right);
   renderView.lookFromAxis(ctkAxesWidget::Left, 10);

+ 7 - 11
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKRenderViewTest2.cpp

@@ -25,9 +25,9 @@
 #include <QDebug>
 
 // VTK includes
-#include <vtkSmartPointer.h>
-#include <vtkRenderer.h>
+#include <vtkNew.h>
 #include <vtkPolyDataMapper.h>
+#include <vtkRenderer.h>
 #include <vtkSphereSource.h>
 
 // CTK includes
@@ -37,10 +37,6 @@
 // STD includes
 #include <iostream>
 
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
-
 //-----------------------------------------------------------------------------
 int ctkVTKRenderViewTest2(int argc, char * argv [] )
 {
@@ -70,17 +66,17 @@ int ctkVTKRenderViewTest2(int argc, char * argv [] )
   renderView.show();
 
   // Instanciate VTK objects
-  VTK_CREATE(vtkSphereSource, sphere);
-  VTK_CREATE(vtkPolyDataMapper, sphereMapper);
-  VTK_CREATE(vtkActor, sphereActor);
+  vtkNew<vtkSphereSource> sphere;
+  vtkNew<vtkPolyDataMapper> sphereMapper;
+  vtkNew<vtkActor> sphereActor;
 
   // Configure actor
   sphere->SetRadius(0.25);
   sphereMapper->SetInputConnection(sphere->GetOutputPort());
-  sphereActor->SetMapper(sphereMapper);
+  sphereActor->SetMapper(sphereMapper.GetPointer());
 
   // Add actor
-  renderView.renderer()->AddActor(sphereActor);
+  renderView.renderer()->AddActor(sphereActor.GetPointer());
 
   renderView.lookFromAxis(ctkAxesWidget::Right);
   renderView.lookFromAxis(ctkAxesWidget::Left, 10);

+ 0 - 4
Libs/Visualization/VTK/Widgets/ctkVTKMagnifyView.cpp

@@ -38,10 +38,6 @@
 // STD includes
 #include <cmath>
 
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
-
 //--------------------------------------------------------------------------
 static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKMagnifyView");
 //--------------------------------------------------------------------------

+ 0 - 4
Libs/Visualization/VTK/Widgets/ctkVTKSliceView.cpp

@@ -39,10 +39,6 @@
 #include <vtkPolyData.h>
 #include <vtkPolyDataMapper2D.h>
 
-// Convenient macro
-#define VTK_CREATE(type, name) \
-  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
-
 // --------------------------------------------------------------------------
 // ctkVTKSliceViewPrivate methods