BioDynaMo  v1.05.120-25dc9790
jit_helper.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_VISUALIZATION_PARAVIEW_JIT_HELPER_H_
16 #define CORE_VISUALIZATION_PARAVIEW_JIT_HELPER_H_
17 
18 #include <string>
19 
20 #include "core/agent/agent.h"
22 #include "core/agent/agent_uid.h"
24 #include "core/functor.h"
25 #include "core/param/param.h"
26 #include "core/resource_manager.h"
27 #include "core/simulation.h"
28 #include "core/util/type.h"
31 
32 #include <vtkNew.h>
33 #include <vtkPointData.h>
34 #include <vtkPoints.h>
35 
36 namespace bdm {
37 
38 // -----------------------------------------------------------------------------
39 template <typename T>
40 struct GetVtkValueType {};
41 
42 // -----------------------------------------------------------------------------
43 template <>
45  using type = real_t;
46 };
47 
48 // -----------------------------------------------------------------------------
49 template <>
50 struct GetVtkValueType<int> {
51  using type = int;
52 };
53 
54 // -----------------------------------------------------------------------------
55 template <>
56 struct GetVtkValueType<uint64_t> {
57  using type = uint64_t;
58 };
59 
60 // -----------------------------------------------------------------------------
61 template <>
63  using type = uint64_t;
64 };
65 
66 // -----------------------------------------------------------------------------
67 template <typename T>
69  using type = uint64_t;
70 };
71 
72 // -----------------------------------------------------------------------------
73 template <typename T, std::size_t N>
74 struct GetVtkValueType<MathArray<T, N>> {
75  using type = typename GetVtkValueType<T>::type;
76 };
77 
78 // -----------------------------------------------------------------------------
79 // -----------------------------------------------------------------------------
80 template <typename T>
82  static const int value = 1;
83 };
84 
85 // -----------------------------------------------------------------------------
86 template <typename T, std::size_t N>
88  static const int value = N;
89 };
90 
91 // -----------------------------------------------------------------------------
92 template <typename T, std::size_t N>
93 struct GetNumberOfComponents<std::array<T, N>> {
94  static const int value = N;
95 };
96 
97 // -----------------------------------------------------------------------------
98 // -----------------------------------------------------------------------------
99 template <typename TClass, typename TDataMember>
101  template <typename TTDataMember = TDataMember>
102  typename std::enable_if<!std::is_same<TTDataMember, Real3>::value>::type
103  operator()(uint64_t tid, const std::string& dm_name, uint64_t dm_offset,
104  VtkAgents* vtk_agents) {
105  using VtkValueType = typename GetVtkValueType<TDataMember>::type;
107  unsigned components = GetNumberOfComponents<TDataMember>::value;
108  vtkNew<VtkArrayType> new_vtk_array;
110  new_vtk_array->Initialize(mode, dm_name, components, dm_offset);
111  auto* vtk_array = new_vtk_array.GetPointer();
112  auto* point_data = vtk_agents->GetData(tid)->GetPointData();
113  point_data->AddArray(vtk_array);
114  }
115 
116  template <typename TTDataMember = TDataMember>
117  typename std::enable_if<std::is_same<TTDataMember, Real3>::value>::type
118  operator()(uint64_t tid, const std::string& dm_name, uint64_t dm_offset,
119  VtkAgents* vtk_agents) {
121  vtkNew<VtkArrayType> new_vtk_array;
123  new_vtk_array->Initialize(mode, dm_name, 3, dm_offset);
124  auto* vtk_array = new_vtk_array.GetPointer();
125  if (dm_name == "position_") {
126  vtkNew<vtkPoints> points;
127  points->SetData(vtk_array);
128  vtk_agents->GetData(tid)->SetPoints(points.GetPointer());
129  } else if (dm_name == "mass_location_") {
130  // create points with position {0, 0, 0}
131  // BDMGlyph will rotate and translate based on the attribute data
132  vtkNew<vtkPoints> points;
133  points->SetData(vtk_array);
134  vtk_agents->GetData(tid)->SetPoints(points.GetPointer());
135  vtk_agents->GetData(tid)->GetPointData()->AddArray(vtk_array);
136  } else {
137  vtk_agents->GetData(tid)->GetPointData()->AddArray(vtk_array);
138  }
139  }
140 };
141 
142 } // namespace bdm
143 
144 #endif // CORE_VISUALIZATION_PARAVIEW_JIT_HELPER_H_
bdm::GetVtkValueType< MathArray< T, N > >::type
typename GetVtkValueType< T >::type type
Definition: jit_helper.h:75
bdm::GetVtkValueType< uint64_t >::type
uint64_t type
Definition: jit_helper.h:57
bdm::Param::mapped_data_array_mode
Param::MappedDataArrayMode mapped_data_array_mode
Definition: param.h:555
bdm::VtkAgents::GetData
vtkUnstructuredGrid * GetData(uint64_t idx)
Definition: vtk_agents.cc:114
agent_uid.h
bdm::CreateVtkDataArray
Definition: jit_helper.h:100
bdm
Definition: agent.cc:39
bdm::AgentPointer
Definition: agent_pointer.h:58
bdm::CreateVtkDataArray::operator()
std::enable_if<!std::is_same< TTDataMember, Real3 >::value >::type operator()(uint64_t tid, const std::string &dm_name, uint64_t dm_offset, VtkAgents *vtk_agents)
Definition: jit_helper.h:103
bdm::GetVtkValueType< AgentUid >::type
uint64_t type
Definition: jit_helper.h:63
bdm::MappedDataArray
Definition: mapped_data_array.h:128
bdm::real_t
double real_t
Definition: real_t.h:21
agent_pointer.h
bdm::GetVtkValueType< AgentPointer< T > >::type
uint64_t type
Definition: jit_helper.h:69
type.h
mapped_data_array.h
bdm::GetNumberOfComponents::value
static const int value
Definition: jit_helper.h:82
bdm::GetVtkValueType< int >::type
int type
Definition: jit_helper.h:51
math_array.h
bdm::VtkAgents
Definition: vtk_agents.h:36
agent.h
bdm::AgentUid
Definition: agent_uid.h:25
std
Definition: agent_uid.h:117
simulation.h
bdm::Simulation::GetParam
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:254
bdm::GetVtkValueType
Definition: jit_helper.h:40
bdm::MathArray
Definition: math_array.h:36
bdm::CreateVtkDataArray::operator()
std::enable_if< std::is_same< TTDataMember, Real3 >::value >::type operator()(uint64_t tid, const std::string &dm_name, uint64_t dm_offset, VtkAgents *vtk_agents)
Definition: jit_helper.h:118
bdm::GetVtkValueType< real_t >::type
real_t type
Definition: jit_helper.h:45
resource_manager.h
param.h
helper.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
functor.h
bdm::GetNumberOfComponents
Definition: jit_helper.h:81