File: vtkEmulatedTimeDummySource.cxx

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 544,220 kB
  • sloc: cpp: 3,374,605; ansic: 1,332,409; python: 150,381; xml: 122,166; sql: 65,887; sh: 7,317; javascript: 5,262; yacc: 4,417; java: 3,977; perl: 2,363; lex: 1,929; f90: 1,397; makefile: 170; objc: 153; tcl: 59; pascal: 50; fortran: 29
file content (144 lines) | stat: -rw-r--r-- 4,662 bytes parent folder | download
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
// SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkEmulatedTimeDummySource.h"

#include "vtkConeSource.h"
#include "vtkCubeSource.h"
#include "vtkDataObject.h"
#include "vtkDemandDrivenPipeline.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkSphereSource.h"
#include "vtkStreamingDemandDrivenPipeline.h"

namespace
{
constexpr unsigned short TIMESTEPS_SIZE = 4;
constexpr double SPHERE_TIMESTEPS[::TIMESTEPS_SIZE] = { 15.50, 16.20, 16.95, 18.10 };
constexpr double CONE_TIMESTEPS[::TIMESTEPS_SIZE] = { 16.70, 17.10, 17.80, 18.40 };
constexpr double CUBE_TIMESTEPS[::TIMESTEPS_SIZE] = { 30.30, 30.80, 31.70, 34.60 };

const double* getCorrespondingTimesteps(int preset)
{
  switch (preset)
  {
    case vtkEmulatedTimeDummySource::SourcePreset::CONE:
      return ::CONE_TIMESTEPS;

    case vtkEmulatedTimeDummySource::SourcePreset::CUBE:
      return ::CUBE_TIMESTEPS;

    case vtkEmulatedTimeDummySource::SourcePreset::SPHERE:
    default:
      return ::SPHERE_TIMESTEPS;
  }
}
}

//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkEmulatedTimeDummySource);

//------------------------------------------------------------------------------
vtkEmulatedTimeDummySource::vtkEmulatedTimeDummySource()
{
  this->SetNumberOfOutputPorts(1);
}

//------------------------------------------------------------------------------
vtkEmulatedTimeDummySource::~vtkEmulatedTimeDummySource() = default;

//------------------------------------------------------------------------------
int vtkEmulatedTimeDummySource::FillOutputPortInformation(
  int vtkNotUsed(port), vtkInformation* info)
{
  // now add our info
  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
  return 1;
}

//------------------------------------------------------------------------------
int vtkEmulatedTimeDummySource::RequestData(vtkInformation* vtkNotUsed(request),
  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
{
  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  double requiredTime = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());

  const double* timesteps = ::getCorrespondingTimesteps(this->SourcePresets);
  requiredTime = std::max(std::min(requiredTime, timesteps[::TIMESTEPS_SIZE - 1]), timesteps[0]);
  vtkPolyData* output = vtkPolyData::GetData(outputVector, 0);

  double completionRatio =
    (requiredTime - timesteps[0]) / (timesteps[::TIMESTEPS_SIZE - 1] - timesteps[0]);
  switch (this->SourcePresets)
  {
    case SourcePreset::CONE:
    {
      vtkNew<vtkConeSource> cone;
      double height = 1 + 2.5 * completionRatio;
      cone->SetHeight(height);
      cone->Update();
      output->ShallowCopy(cone->GetOutput());
      break;
    }

    case SourcePreset::CUBE:
    {
      vtkNew<vtkCubeSource> cube;
      double size = 1 + 2 * completionRatio;
      cube->SetCenter(0, size, 0);
      cube->Update();
      output->ShallowCopy(cube->GetOutput());
      break;
    }

    case SourcePreset::SPHERE:
    default:
    {
      vtkNew<vtkSphereSource> sphere;
      double theta = 90 + 180 * completionRatio;
      sphere->SetStartTheta(theta);
      sphere->Update();
      output->ShallowCopy(sphere->GetOutput());
      break;
    }
  }
  return 1;
}

//------------------------------------------------------------------------------
int vtkEmulatedTimeDummySource::RequestInformation(vtkInformation* vtkNotUsed(request),
  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
{
  vtkInformation* outInfo = outputVector->GetInformationObject(0);

  const double* timesteps = ::getCorrespondingTimesteps(this->SourcePresets);

  double timeRange[2];
  timeRange[0] = timesteps[0];
  timeRange[1] = timesteps[::TIMESTEPS_SIZE - 1];
  outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), timesteps, ::TIMESTEPS_SIZE);
  outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
  return 1;
}

//------------------------------------------------------------------------------
void vtkEmulatedTimeDummySource::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "SourcePresets: ";
  switch (this->SourcePresets)
  {
    case vtkEmulatedTimeDummySource::SourcePreset::CONE:
      os << "Cone";

    case vtkEmulatedTimeDummySource::SourcePreset::CUBE:
      os << "Cube";

    case vtkEmulatedTimeDummySource::SourcePreset::SPHERE:
    default:
      os << "Sphere";
  }
  os << "\n";
}