CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxVNNclAlgorithm.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXVNNCLALGORITHM_H_
34 #define CXVNNCLALGORITHM_H_
35 
36 //TODO remove, should be defined in oul instead
37 #define __CL_ENABLE_EXCEPTIONS //telling the opencl c++ wrapper to throw exceptions
38 
39 #include "cxUSFrameData.h"
40 #include "OpenCLManager.hpp"
41 #include "RuntimeMeasurementManager.hpp"
42 
43 namespace cx
44 {
49 {
50 public:
53 
60  typedef struct __frameBlock_t
61  {
62  unsigned char* data;
63  size_t length;
64  } frameBlock_t;
65 
82  virtual bool initCL(QString kernelFile,
83  int nMaxPlanes,
84  int nPlanes,
85  int method,
86  int planeMethod,
87  int nStarts,
88  float brightnessWeight,
89  float newnessWeight);
102  virtual cl::Program buildCLProgram(std::string program_src, std::string kernelPath,
103  int nMaxPlanes,
104  int nPlanes,
105  int method,
106  int planeMethod,
107  int nStarts,
108  float brightnessWeight,
109  float newnessWeight);
120  virtual bool reconstruct(ProcessedUSInputDataPtr input,
121  vtkImageDataPtr outputData,
122  float radius,
123  int nClosePlanes);
124 
134  virtual bool initializeFrameBlocks(frameBlock_t* framePointers,
135  int numBlocks,
136  ProcessedUSInputDataPtr inputFrames);
144  virtual void freeFrameBlocks(frameBlock_t* framePointers,
145  int numBlock);
146 
147 
161  virtual void fillPlaneMatrices(float *planeMatrices,
163 
167  void setProfiling(bool on);
168  double getTotalExecutionTime();
169  double getKernelExecutionTime();
170 
171 private:
172  void setKernelArguments(
173  cl::Kernel kernel,
174  int volume_xsize,
175  int volume_ysize,
176  int volume_zsize,
177  float volume_xspacing,
178  float volume_yspacing,
179  float volume_zspacing,
180  int in_xsize,
181  int in_ysize,
182  float in_xspacing,
183  float in_yspacing,
184  std::vector<cl::Buffer>& blocks,
185  cl::Buffer out_volume,
186  cl::Buffer plane_matrices,
187  cl::Buffer mask,
188  size_t plane_eqs_size,
189  size_t close_planes_size,
190  float radius);
191  size_t calculateSpaceNeededForClosePlanes(cl::Kernel kernel, cl::Device device, size_t local_work_size, size_t nPlanes_numberOfInputImages, int nClosePlanes);
192  bool isUsingTooMuchMemory(size_t outputVolumeSize, size_t inputBlocksLength, cl_ulong globalMemUse);
193  void measureAndExecuteKernel(cl::CommandQueue queue, cl::Kernel kernel, size_t global_work_size, size_t local_work_size, std::string measurementName);
194  void measureAndReadBuffer(cl::CommandQueue queue, cl::Buffer outputBuffer, size_t outputVolumeSize, void *outputData, std::string measurementName);
195 
196  void startProfiling(std::string name, cl::CommandQueue queue);
197  void stopProfiling(std::string name, cl::CommandQueue queue);
198 
199  cl::Kernel mKernel;
200  oul::ContextPtr mOulContex;
201  oul::RuntimeMeasurementsManagerPtr mRuntime;
202  std::set<std::string> mMeasurementNames;
203  std::string mKernelMeasurementName;
204 
205 };
206 
207 typedef boost::shared_ptr<VNNclAlgorithm> VNNclAlgorithmPtr;
208 
209 } /* namespace cx */
210 #endif /* CXVNNCLALGORITHM_H_ */
virtual bool initCL(QString kernelFile, int nMaxPlanes, int nPlanes, int method, int planeMethod, int nStarts, float brightnessWeight, float newnessWeight)
struct cx::VNNclAlgorithm::__frameBlock_t frameBlock_t
virtual void freeFrameBlocks(frameBlock_t *framePointers, int numBlock)
virtual void fillPlaneMatrices(float *planeMatrices, ProcessedUSInputDataPtr input)
virtual cl::Program buildCLProgram(std::string program_src, std::string kernelPath, int nMaxPlanes, int nPlanes, int method, int planeMethod, int nStarts, float brightnessWeight, float newnessWeight)
virtual bool reconstruct(ProcessedUSInputDataPtr input, vtkImageDataPtr outputData, float radius, int nClosePlanes)
virtual bool initializeFrameBlocks(frameBlock_t *framePointers, int numBlocks, ProcessedUSInputDataPtr inputFrames)
void setProfiling(bool on)
boost::shared_ptr< class ProcessedUSInputData > ProcessedUSInputDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
boost::shared_ptr< VNNclAlgorithm > VNNclAlgorithmPtr