-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkDateTimeAnnotation.cxx
145 lines (117 loc) · 4.56 KB
/
vtkDateTimeAnnotation.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
/*=========================================================================
Program: ParaView
Module: $RCSfile: vtkJulianDayToTextConvertor.cxx,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkDateTimeAnnotation.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
vtkStandardNewMacro(vtkDateTimeAnnotation);
//----------------------------------------------------------------------------
vtkDateTimeAnnotation::vtkDateTimeAnnotation()
{
this->Format = 0;
this->Shift = 0.0;
this->Scale = 1.0;
this->UTCOffset = 0;
this->SetFormat("Time: %04i/%02i/%02i %02i:%02i:%02i"); // YYYY/MM/DD HH:MM:SS
}
//----------------------------------------------------------------------------
vtkDateTimeAnnotation::~vtkDateTimeAnnotation()
{
this->SetFormat(0);
this->UTCOffset = 0;
}
//----------------------------------------------------------------------------
int vtkDateTimeAnnotation::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
return 1;
}
//----------------------------------------------------------------------------
int vtkDateTimeAnnotation::RequestInformation(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
if (!this->Superclass::RequestInformation(
request, inputVector, outputVector))
{
return 0;
}
double timeRange[2];
timeRange[0] = VTK_DOUBLE_MIN;
timeRange[1] = VTK_DOUBLE_MAX;
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
return 1;
}
//----------------------------------------------------------------------------
inline double vtkDateTimeAnnotation_ForwardConvert(double T0, double shift, double scale)
{
return T0*scale + shift;
}
//----------------------------------------------------------------------------
int vtkDateTimeAnnotation::RequestData(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkDataObject* input = vtkDataObject::GetData(inputVector[0]);
vtkTable* output = vtkTable::GetData(outputVector);
char *buffer = new char[strlen(this->Format)+1024];
strcpy(buffer, "?");
vtkInformation* inputInfo = input? input->GetInformation() : 0;
vtkInformation* outputInfo = outputVector->GetInformationObject(0);
double time = 0;
if (inputInfo && inputInfo->Has(vtkDataObject::DATA_TIME_STEP())
&& this->Format)
{
time = inputInfo->Get(vtkDataObject::DATA_TIME_STEP());//[0];
}
else if (outputInfo &&
outputInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
&& this->Format)
{
time = outputInfo->Get(
vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());//[0];
}
time = vtkDateTimeAnnotation_ForwardConvert(time, this->Shift, this->Scale);
const ptime epoch = boost::posix_time::from_time_t(0);
boost::posix_time::time_duration UTC_offset = boost::posix_time::hours(UTCOffset);
ptime datetime = epoch + seconds(static_cast<long>(time)) + UTC_offset;
std::tm tm = boost::posix_time::to_tm(datetime);
int year = tm.tm_year + 1900; //convert from epoch
int month = tm.tm_mon + 1;//conert jan == 0
int day = tm.tm_mday; //starts at 1, ok
int hour = tm.tm_hour; // 0 = midnight, ok
int min = tm.tm_min; // 0, ok
int sec = tm.tm_sec; // [0,60] in c++11, ok http://en.cppreference.com/w/cpp/chrono/c/tm
sprintf(buffer, this->Format, year, month, day,hour,min,sec);
vtkStringArray* data = vtkStringArray::New();
data->SetName("Text");
data->SetNumberOfComponents(1);
data->InsertNextValue(buffer);
output->AddColumn(data);
data->Delete();
delete[] buffer;
return 1;
}
//----------------------------------------------------------------------------
void vtkDateTimeAnnotation::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Format: "
<< (this->Format? this->Format : "(none)") << endl;
}