1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestTecPlotReader2.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 // .NAME Test of vtkTecplotReader
16 // .SECTION Description
17 //
18
19 #include "vtkDebugLeaks.h"
20 #include "vtkTecplotReader.h"
21
22 #include "vtkActor.h"
23 #include "vtkArrayIterator.h"
24 #include "vtkArrayIteratorTemplate.h"
25 #include "vtkCallbackCommand.h"
26 #include "vtkCamera.h"
27 #include "vtkCompositeDataGeometryFilter.h"
28 #include "vtkCompositeDataPipeline.h"
29 #include "vtkDirectory.h"
30 #include "vtkPointData.h"
31 #include "vtkPolyDataMapper.h"
32 #include "vtkRegressionTestImage.h"
33 #include "vtkRenderWindow.h"
34 #include "vtkRenderWindowInteractor.h"
35 #include "vtkRenderer.h"
36 #include "vtkSmartPointer.h"
37 #include "vtkStringArray.h"
38 #include "vtkTestUtilities.h"
39 #include <string>
40 #include <vtksys/SystemTools.hxx>
41
42 class vtkErrorObserver
43 {
44
45 public:
Reset()46 static void Reset()
47 {
48 HasError = false;
49 ErrorMessage.clear();
50 }
51
OnError(vtkObject * vtkNotUsed (caller),unsigned long int vtkNotUsed (eventId),void * vtkNotUsed (clientData),void * callData)52 static void OnError(vtkObject* vtkNotUsed(caller), unsigned long int vtkNotUsed(eventId),
53 void* vtkNotUsed(clientData), void* callData)
54 {
55 HasError = true;
56 char* pString = (char*)callData;
57 if (pString)
58 {
59 ErrorMessage = pString;
60 }
61 }
62
63 static bool HasError;
64 static std::string ErrorMessage;
65 };
66
67 bool vtkErrorObserver::HasError = false;
68 std::string vtkErrorObserver::ErrorMessage = std::string();
69
TestTecplotReader2(int argc,char * argv[])70 int TestTecplotReader2(int argc, char* argv[])
71 {
72 char* dataRoot = vtkTestUtilities::GetDataRoot(argc, argv);
73 const std::string tecplotDir = std::string(dataRoot) + "/Data/TecPlot/";
74
75 if (argc < 2)
76 {
77 return EXIT_SUCCESS;
78 }
79
80 const char* filename = argv[1];
81
82 vtkNew<vtkCallbackCommand> cmd;
83 cmd->SetCallback(&(vtkErrorObserver::OnError));
84
85 const std::string ext = vtksys::SystemTools::GetFilenameLastExtension(filename);
86 if (ext != ".dat")
87 {
88 return EXIT_FAILURE;
89 }
90
91 vtkErrorObserver::Reset();
92 vtkNew<vtkTecplotReader> r;
93 r->AddObserver("ErrorEvent", cmd);
94 r->SetFileName((tecplotDir + filename).c_str());
95 r->Update();
96 r->RemoveAllObservers();
97
98 vtkMultiBlockDataSet* ds = r->GetOutput();
99 if (ds == nullptr)
100 {
101 cerr << "Failed to read data set from " << filename << endl;
102 return EXIT_FAILURE;
103 }
104 if (vtkErrorObserver::HasError)
105 {
106 cerr << "Failed to read from " << filename << endl;
107 if (!vtkErrorObserver::ErrorMessage.empty())
108 {
109 cerr << "Error message: " << vtkErrorObserver::ErrorMessage << endl;
110 }
111 return EXIT_FAILURE;
112 }
113
114 cout << filename << " was read without errors." << endl;
115 delete[] dataRoot;
116 return EXIT_SUCCESS;
117 }
118