-
Notifications
You must be signed in to change notification settings - Fork 122
/
vtkMDEWSource.cxx
350 lines (312 loc) · 8.57 KB
/
vtkMDEWSource.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#include "vtkMDEWSource.h"
#include "vtkBox.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPVClipDataSet.h"
#include "vtkPVInformationKeys.h"
#include "vtkUnstructuredGridAlgorithm.h"
#include "vtkUnstructuredGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "MantidVatesAPI/BoxInfo.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidVatesAPI/MDEWInMemoryLoadingPresenter.h"
#include "MantidVatesAPI/MDLoadingViewAdapter.h"
#include "MantidVatesAPI/ADSWorkspaceProvider.h"
#include "MantidVatesAPI/vtkMDHexFactory.h"
#include "MantidVatesAPI/vtkMDQuadFactory.h"
#include "MantidVatesAPI/vtkMDLineFactory.h"
#include "MantidVatesAPI/vtkMD0DFactory.h"
#include "MantidVatesAPI/FilteringUpdateProgressAction.h"
#include "MantidVatesAPI/IgnoreZerosThresholdRange.h"
#include "MantidKernel/WarningSuppressions.h"
#include <boost/optional.hpp>
using namespace Mantid::VATES;
vtkStandardNewMacro(vtkMDEWSource)
/// Constructor
vtkMDEWSource::vtkMDEWSource() : m_wsName(""), m_depth(1000), m_time(0), m_presenter(NULL), m_normalization(AutoSelect)
{
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(1);
}
/// Destructor
vtkMDEWSource::~vtkMDEWSource()
{
delete m_presenter;
}
/*
Setter for the recursion depth
@param depth : recursion depth to use
*/
void vtkMDEWSource::SetDepth(int depth)
{
size_t temp = depth;
if(m_depth != temp)
{
this->m_depth = temp;
this->Modified();
}
}
/*
Setter for the workspace name.
@param name : workspace name to extract from ADS.
*/
void vtkMDEWSource::SetWsName(std::string name)
{
if(m_wsName != name && name != "")
{
m_wsName = name;
this->Modified();
}
}
/**
Gets the geometry xml from the workspace. Allows object panels to configure themeselves.
@return geometry xml const * char reference.
*/
const char* vtkMDEWSource::GetInputGeometryXML()
{
if(m_presenter == NULL)
{
return "";
}
try
{
return m_presenter->getGeometryXML().c_str();
}
catch(std::runtime_error&)
{
return "";
}
}
/**
* Gets the current value of the special coordinates associated with the
* workspace.
* @return the special coordinates value
*/
int vtkMDEWSource::GetSpecialCoordinates()
{
if (NULL == m_presenter)
{
return 0;
}
try
{
return m_presenter->getSpecialCoordinates();
}
catch (std::runtime_error &)
{
return 0;
}
}
/**
* Gets the minimum value of the data associated with the
* workspace.
* @return The minimum value of the workspace data.
*/
double vtkMDEWSource::GetMinValue()
{
if (NULL == m_presenter)
{
return 0.0;
}
try
{
return m_presenter->getMinValue();
}
catch (std::runtime_error &)
{
return 0;
}
}
/**
* Gets the maximum value of the data associated with the
* workspace.
* @return The maximum value of the workspace data.
*/
double vtkMDEWSource::GetMaxValue()
{
if (NULL == m_presenter)
{
return 0.0;
}
try
{
return m_presenter->getMaxValue();
}
catch (std::runtime_error &)
{
return 0;
}
}
/**
* Gets the (first) instrument which is associated with the workspace.
* @return The name of the instrument.
*/
const char* vtkMDEWSource::GetInstrument()
{
if (NULL == m_presenter)
{
return "";
}
try
{
return m_presenter->getInstrument().c_str();
}
catch (std::runtime_error &)
{
return "";
}
}
/**
Set the normalization option. This is how the signal data will be normalized before viewing.
@param option : Normalization option
*/
void vtkMDEWSource::SetNormalization(int option)
{
m_normalization = static_cast<Mantid::VATES::VisualNormalization>(option);
this->Modified();
}
int vtkMDEWSource::RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector)
{
if(m_presenter->canReadFile())
{
using namespace Mantid::VATES;
//get the info objects
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
// usually only one actual step requested
m_time =outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
}
FilterUpdateProgressAction<vtkMDEWSource> loadingProgressUpdate(this, "Loading...");
FilterUpdateProgressAction<vtkMDEWSource> drawingProgressUpdate(this, "Drawing...");
ThresholdRange_scptr thresholdRange(new IgnoreZerosThresholdRange());
vtkMD0DFactory* zeroDFactory = new vtkMD0DFactory;
vtkMDHexFactory* hexahedronFactory = new vtkMDHexFactory(thresholdRange, m_normalization);
vtkMDQuadFactory* quadFactory = new vtkMDQuadFactory(thresholdRange, m_normalization);
vtkMDLineFactory* lineFactory = new vtkMDLineFactory(thresholdRange, m_normalization);
hexahedronFactory->SetSuccessor(quadFactory);
quadFactory->SetSuccessor(lineFactory);
lineFactory->SetSuccessor(zeroDFactory);
hexahedronFactory->setTime(m_time);
vtkDataSet* product = m_presenter->execute(hexahedronFactory, loadingProgressUpdate, drawingProgressUpdate);
//-------------------------------------------------------- Corrects problem whereby boundaries not set propertly in PV.
vtkBox* box = vtkBox::New();
box->SetBounds(product->GetBounds());
vtkPVClipDataSet* clipper = vtkPVClipDataSet::New();
clipper->SetInputData(product);
clipper->SetClipFunction(box);
clipper->SetInsideOut(true);
clipper->Update();
vtkDataSet* clipperOutput = clipper->GetOutput();
//--------------------------------------------------------
vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->ShallowCopy(clipperOutput);
m_presenter->setAxisLabels(output);
clipper->Delete();
}
return 1;
}
GCC_DIAG_OFF(strict-aliasing)
int vtkMDEWSource::RequestInformation(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector)
{
if(m_presenter == NULL && !m_wsName.empty())
{
m_presenter = new MDEWInMemoryLoadingPresenter(new MDLoadingViewAdapter<vtkMDEWSource>(this), new ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace>, m_wsName);
if(!m_presenter->canReadFile())
{
vtkErrorMacro(<<"Cannot fetch the specified workspace from Mantid ADS.");
}
else
{
// If the MDEvent workspace has had top level splitting applied to it, then use the a depth of 1
if (auto split = Mantid::VATES::findRecursionDepthForTopLevelSplitting(m_wsName)) {
SetDepth(split.get());
}
m_presenter->executeLoadMetadata();
setTimeRange(outputVector);
}
}
return 1;
}
void vtkMDEWSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/** Helper function to setup the time range.
@param outputVector : vector onto which the time range will be set.
*/
void vtkMDEWSource::setTimeRange(vtkInformationVector* outputVector)
{
if(m_presenter->hasTDimensionAvailable())
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkPVInformationKeys::TIME_LABEL_ANNOTATION(),
m_presenter->getTimeStepLabel().c_str());
std::vector<double> timeStepValues = m_presenter->getTimeStepValues();
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &timeStepValues[0],
static_cast<int> (timeStepValues.size()));
double timeRange[2];
timeRange[0] = timeStepValues.front();
timeRange[1] = timeStepValues.back();
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
}
}
/*
Getter for the recursion depth.
@return depth
*/
size_t vtkMDEWSource::getRecursionDepth() const
{
return this->m_depth;
}
/*
Getter for the load in memory status
@return true.
*/
bool vtkMDEWSource::getLoadInMemory() const
{
return true;
}
/*Getter for the time
@return the time.
*/
double vtkMDEWSource::getTime() const
{
return m_time;
}
/*
Setter for the algorithm progress.
@param progress : progress increment
@param message : progress message
*/
void vtkMDEWSource::updateAlgorithmProgress(double progress, const std::string& message)
{
this->SetProgressText(message.c_str());
this->SetProgress(progress);
}
/*
Getter for the workspace type name.
*/
char* vtkMDEWSource::GetWorkspaceTypeName()
{
if(m_presenter == NULL)
{
return const_cast<char*>("");
}
try
{
//Forward request on to MVP presenter
typeName = m_presenter->getWorkspaceTypeName();
return const_cast<char*>(typeName.c_str());
}
catch(std::runtime_error&)
{
return const_cast<char*>("");
}
}
const char* vtkMDEWSource::GetWorkspaceName()
{
return m_wsName.c_str();
}