GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSTube.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS is free software: you can redistribute it and/or modify *
5 // * it under the terms of the GNU General Public License as published by *
6 // * the Free Software Foundation, either version 3 of the License, or *
7 // * (at your option) any later version. *
8 // * *
9 // * GGEMS is distributed in the hope that it will be useful, *
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 // * GNU General Public License for more details. *
13 // * *
14 // * You should have received a copy of the GNU General Public License *
15 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
34 
38 
39 GGEMSTube::GGEMSTube(GGfloat const& radius_x, GGfloat const& radius_y, GGfloat const& height, std::string const& unit)
40 : GGEMSVolume()
41 {
42  GGcout("GGEMSTube", "GGEMSTube", 3) << "GGEMSTube creating..." << GGendl;
43 
44  height_ = DistanceUnit(height, unit);
45  radius_x_ = DistanceUnit(radius_x, unit);
46  radius_y_ = DistanceUnit(radius_y, unit);
47 
48  GGcout("GGEMSTube", "GGEMSTube", 3) << "GGEMSTube created!!!" << GGendl;
49 }
50 
54 
56 {
57  GGcout("GGEMSTube", "~GGEMSTube", 3) << "GGEMSTube erasing..." << GGendl;
58 
59  GGcout("GGEMSTube", "~GGEMSTube", 3) << "GGEMSTube erased!!!" << GGendl;
60 }
61 
65 
67 {
68  GGcout("GGEMSTube", "Initialize", 3) << "Initializing GGEMSTube solid volume..." << GGendl;
69 
70  // Getting the path to kernel
71  std::string const kOpenCLKernelPath = OPENCL_KERNEL_PATH;
72  std::string const kFilename = kOpenCLKernelPath + "/DrawGGEMSTube.cl";
73 
74  // Get the volume creator manager
76 
77  // Get the OpenCL manager
79 
80  // Get the data type and compiling kernel
81  std::string const kDataType = "-D" + volume_creator_manager.GetDataType();
82  opencl_manager.CompileKernel(kFilename, "draw_ggems_tube", kernel_draw_volume_, nullptr, const_cast<char*>(kDataType.c_str()));
83 }
84 
88 
89 void GGEMSTube::Draw(void)
90 {
91  GGcout("GGEMSTube", "Draw", 3) << "Drawing Tube..." << GGendl;
92 
93  // Get the OpenCL manager
95 
96  // Get the volume creator manager
98 
99  // Get command queue and event
100  cl::CommandQueue* queue = opencl_manager.GetCommandQueue(0);
101  cl::Event* event = opencl_manager.GetEvent(0);
102 
103  // Get Device name and storing methode name + device
104  GGsize device_index = opencl_manager.GetIndexOfActivatedDevice(0);
105  std::string device_name = opencl_manager.GetDeviceName(device_index);
106  std::ostringstream oss(std::ostringstream::out);
107  oss << "GGEMSTube::Draw on " << device_name << ", index " << device_index;
108 
109  // Get parameters from phantom creator
110  GGfloat3 voxel_sizes = volume_creator_manager.GetElementsSizes();
111 
112  GGint3 phantom_dimensions;
113  phantom_dimensions.x = static_cast<GGint>(volume_creator_manager.GetVolumeDimensions().x_);
114  phantom_dimensions.y = static_cast<GGint>(volume_creator_manager.GetVolumeDimensions().y_);
115  phantom_dimensions.z = static_cast<GGint>(volume_creator_manager.GetVolumeDimensions().z_);
116 
117  GGsize number_of_elements = volume_creator_manager.GetNumberElements();
118  cl::Buffer* voxelized_phantom = volume_creator_manager.GetVoxelizedVolume();
119 
120  // Getting work group size, and work-item number
121  GGsize work_group_size = opencl_manager.GetWorkGroupSize();
122  GGsize number_of_work_items = opencl_manager.GetBestWorkItem(number_of_elements);
123 
124  // Parameters for work-item in kernel
125  cl::NDRange global_wi(number_of_work_items);
126  cl::NDRange local_wi(work_group_size);
127 
128  // Set parameters for kernel
129  kernel_draw_volume_[0]->setArg(0, number_of_elements);
130  kernel_draw_volume_[0]->setArg(1, voxel_sizes);
131  kernel_draw_volume_[0]->setArg(2, phantom_dimensions);
132  kernel_draw_volume_[0]->setArg(3, positions_);
133  kernel_draw_volume_[0]->setArg(4, label_value_);
134  kernel_draw_volume_[0]->setArg(5, height_);
135  kernel_draw_volume_[0]->setArg(6, radius_x_);
136  kernel_draw_volume_[0]->setArg(7, radius_y_);
137  kernel_draw_volume_[0]->setArg(8, *voxelized_phantom);
138 
139  // Launching kernel
140  GGint kernel_status = queue->enqueueNDRangeKernel(*kernel_draw_volume_[0], 0, global_wi, local_wi, nullptr, event);
141  opencl_manager.CheckOpenCLError(kernel_status, "GGEMSTube", "Draw");
142 
143  // GGEMS Profiling
145  profiler_manager.HandleEvent(*event, oss.str());
146 
147  queue->finish();
148 }
149 
153 
154 GGEMSTube* create_tube(GGfloat const radius_x, GGfloat const radius_y, GGfloat const height, char const* unit)
155 {
156  return new(std::nothrow) GGEMSTube(radius_x, radius_y, height, unit);
157 }
158 
162 
164 {
165  if (tube) {
166  delete tube;
167  tube = nullptr;
168  }
169 }
170 
174 
175 void set_position_tube(GGEMSTube* tube, GGfloat const pos_x, GGfloat const pos_y, GGfloat const pos_z, char const* unit)
176 {
177  tube->SetPosition(pos_x, pos_y, pos_z, unit);
178 }
179 
183 
184 void set_material_tube(GGEMSTube* tube, char const* material)
185 {
186  tube->SetMaterial(material);
187 }
188 
192 
193 void set_label_value_tube(GGEMSTube* tube, GGfloat const label_value)
194 {
195  tube->SetLabelValue(label_value);
196 }
197 
201 
203 {
204  tube->Initialize();
205 }
206 
210 
211 void draw_tube(GGEMSTube* tube)
212 {
213  tube->Draw();
214 }
GGEMSVolumeCreatorManager::GetElementsSizes
GGfloat3 GetElementsSizes() const
size of voxels in the voxelized volume
Definition: GGEMSVolumeCreatorManager.hh:116
GGEMSVolume::kernel_draw_volume_
cl::Kernel ** kernel_draw_volume_
Definition: GGEMSVolume.hh:120
GGEMSVolumeCreatorManager::GetNumberElements
GGsize GetNumberElements(void) const
Return the total number of voxels.
Definition: GGEMSVolumeCreatorManager.hh:147
GGEMSTube::height_
GGfloat height_
Definition: GGEMSTube.hh:98
GGEMSVolume
Mother class handle volume.
Definition: GGEMSVolume.hh:41
GGEMSVolumeCreatorManager::GetDataType
std::string GetDataType(void) const
get the type of data
Definition: GGEMSVolumeCreatorManager.hh:154
GGEMSVolumeCreatorManager::GetInstance
static GGEMSVolumeCreatorManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSVolumeCreatorManager.hh:67
GGEMSProfilerManager::GetInstance
static GGEMSProfilerManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSProfilerManager.hh:66
GGEMSTube::radius_y_
GGfloat radius_y_
Definition: GGEMSTube.hh:100
GGEMSOpenCLManager::CheckOpenCLError
void CheckOpenCLError(GGint const &error, std::string const &class_name, std::string const &method_name) const
check the OpenCL error
Definition: GGEMSOpenCLManager.cc:1048
GGEMSTube::Initialize
void Initialize(void) override
Initialize the solid and store it in Phantom creator manager.
Definition: GGEMSTube.cc:66
GGEMSVolumeCreatorManager::GetVoxelizedVolume
cl::Buffer * GetVoxelizedVolume(void) const
Return the voxelized volume on OpenCL device.
Definition: GGEMSVolumeCreatorManager.hh:161
GGEMSOpenCLManager::GetBestWorkItem
GGsize GetBestWorkItem(GGsize const &number_of_elements) const
get the best number of work item
Definition: GGEMSOpenCLManager.cc:1030
GGEMSOpenCLManager::GetEvent
cl::Event * GetEvent(GGsize const &thread_index) const
return an event to activated context
Definition: GGEMSOpenCLManager.hh:230
GGEMSVolume::label_value_
GGfloat label_value_
Definition: GGEMSVolume.hh:118
set_position_tube
void set_position_tube(GGEMSTube *tube, GGfloat const pos_x, GGfloat const pos_y, GGfloat const pos_z, char const *unit)
Set the position of the tube.
Definition: GGEMSTube.cc:175
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
set_label_value_tube
void set_label_value_tube(GGEMSTube *tube, GGfloat const label_value)
Set the label value in tube.
Definition: GGEMSTube.cc:193
GGint
#define GGint
Definition: GGEMSTypes.hh:224
draw_tube
void draw_tube(GGEMSTube *tube)
Draw analytical volume in voxelized phantom.
Definition: GGEMSTube.cc:211
GGEMSTube::radius_x_
GGfloat radius_x_
Definition: GGEMSTube.hh:99
GGEMSProfilerManager
GGEMS class managing profiler data.
Definition: GGEMSProfilerManager.hh:48
GGsize3_t::z_
GGsize z_
Definition: GGEMSTypes.hh:270
GGEMSOpenCLManager::GetWorkGroupSize
GGsize GetWorkGroupSize(void) const
Get the work group size defined in GGEMS on activated OpenCL context.
Definition: GGEMSOpenCLManager.hh:198
GGEMSVolumeCreatorManager
Singleton class handling convertion from analytical volume to voxelized volume.
Definition: GGEMSVolumeCreatorManager.hh:49
GGEMSTube::~GGEMSTube
~GGEMSTube(void)
GGEMSTube destructor.
Definition: GGEMSTube.cc:55
set_material_tube
void set_material_tube(GGEMSTube *tube, char const *material)
Set the material of the tube.
Definition: GGEMSTube.cc:184
GGfloat3
#define GGfloat3
Definition: GGEMSTypes.hh:275
GGEMSTube.hh
Class GGEMSTube inheriting from GGEMSVolume handling Tube solid.
GGEMSTube
Class GGEMSTube inheriting from GGEMSVolume handling Tube solid.
Definition: GGEMSTube.hh:41
GGEMSVolume::SetLabelValue
void SetLabelValue(GGfloat const &label_value)
Set the label value.
Definition: GGEMSVolume.cc:74
GGEMSOpenCLManager::CompileKernel
void CompileKernel(std::string const &kernel_filename, std::string const &kernel_name, cl::Kernel **kernel_list, char *const custom_options=nullptr, char *const additional_options=nullptr)
Compile the OpenCL kernel on the activated device.
Definition: GGEMSOpenCLManager.cc:849
GGEMSVolumeCreatorManager::GetVolumeDimensions
GGsize3 GetVolumeDimensions() const
dimensions of volume
Definition: GGEMSVolumeCreatorManager.hh:133
GGEMSTube::Draw
void Draw(void) override
Draw analytical volume in voxelized phantom.
Definition: GGEMSTube.cc:89
GGEMSVolume::positions_
GGfloat3 positions_
Definition: GGEMSVolume.hh:119
GGcout
GGEMSStream GGcout
Definition: GGEMSPrint.cc:34
GGEMSSystemOfUnits.hh
Namespace storing all the usefull physical units.
GGsize3_t::x_
GGsize x_
Definition: GGEMSTypes.hh:268
create_tube
GGEMSTube * create_tube(GGfloat const radius_x, GGfloat const radius_y, GGfloat const height, char const *unit)
Create instance of GGEMSTube.
Definition: GGEMSTube.cc:154
GGendl
#define GGendl
overload C++ std::endl
Definition: GGEMSPrint.hh:60
GGEMSOpenCLManager
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
Definition: GGEMSOpenCLManager.hh:54
delete_tube
void delete_tube(GGEMSTube *tube)
Delete instance of GGEMSTube.
Definition: GGEMSTube.cc:163
GGEMSOpenCLManager::GetDeviceName
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
Definition: GGEMSOpenCLManager.hh:145
GGEMSProfilerManager.hh
GGEMS class managing profiler data.
GGEMSVolume::SetPosition
void SetPosition(GGfloat const &pos_x, GGfloat const &pos_y, GGfloat const &pos_z, std::string const &unit="mm")
Set the solid phantom position.
Definition: GGEMSVolume.cc:92
GGint3
#define GGint3
Definition: GGEMSTypes.hh:226
GGEMSProfilerManager::HandleEvent
void HandleEvent(cl::Event event, std::string const &profile_name)
handle an OpenCL event in profile_name type
Definition: GGEMSProfilerManager.cc:75
GGEMSOpenCLManager::GetIndexOfActivatedDevice
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
Definition: GGEMSOpenCLManager.hh:175
GGEMSTube::GGEMSTube
GGEMSTube(GGfloat const &radius_x, GGfloat const &radius_y, GGfloat const &height, std::string const &unit="mm")
GGEMSTube constructor.
Definition: GGEMSTube.cc:39
GGEMSOpenCLManager::GetCommandQueue
cl::CommandQueue * GetCommandQueue(GGsize const &thread_index) const
Return the command queue to activated context.
Definition: GGEMSOpenCLManager.hh:222
DistanceUnit
T DistanceUnit(T const &value, std::string const &unit)
Choose best distance unit.
Definition: GGEMSSystemOfUnits.hh:243
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273
GGEMSOpenCLManager::GetInstance
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSOpenCLManager.hh:72
initialize_tube
void initialize_tube(GGEMSTube *tube)
Initialize the solid and store it in Phantom creator manager.
Definition: GGEMSTube.cc:202
GGsize3_t::y_
GGsize y_
Definition: GGEMSTypes.hh:269
GGEMSVolume::SetMaterial
void SetMaterial(std::string const &material)
set the material, Air by default
Definition: GGEMSVolume.cc:79