Newer
Older
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
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "Adaptor.h"
#include <vtkCPDataDescription.h>
#include <vtkCPInputDataDescription.h>
#include <vtkCPProcessor.h>
#include <vtkCPPythonScriptPipeline.h>
#include <vtkNew.h>
#include <vtkUnstructuredGrid.h>
#include "MeshLib/Mesh.h"
#include "MeshLib/Vtk/VtkMappedMeshSource.h"
namespace InSituLib
{
vtkCPProcessor* Processor = NULL;
void Initialize(BaseLib::ConfigTree const & scripts_config, std::string const & path)
{
if (Processor == NULL)
{
Processor = vtkCPProcessor::New();
Processor->Initialize();
}
else
{
Processor->RemoveAllPipelines();
}
for (auto script_config : scripts_config.getConfigSubtreeList("script"))
{
std::stringstream ss;
ss << path << script_config.getConfigParameter<std::string>("name");
vtkNew<vtkCPPythonScriptPipeline> pipeline;
pipeline->Initialize(ss.str().c_str());
Processor->AddPipeline(pipeline.GetPointer());
}
}
void Finalize()
{
if (Processor)
{
Processor->Delete();
Processor = NULL;
}
}
void CoProcess(MeshLib::Mesh const& mesh, double const time,
unsigned int const timeStep, bool const lastTimeStep)
{
vtkNew<vtkCPDataDescription> dataDescription;
dataDescription->AddInput("input");
dataDescription->SetTimeData(time, timeStep);
if (lastTimeStep == true)
{
// assume that we want to all the pipelines to execute if it
// is the last time step.
dataDescription->ForceOutputOn();
}
if (Processor->RequestDataDescription(dataDescription.GetPointer()) != 0)
{
INFO("Start InSitu process.");
vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
vtkSource->SetMesh(&mesh);
vtkSource->Update();
dataDescription->GetInputDescriptionByName("input")->SetGrid(vtkSource->GetOutput());
Processor->CoProcess(dataDescription.GetPointer());
INFO("End InSitu process.");
}
}
} // namespace