Fraxinus  16.5.0-fx-rc5
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);
103  virtual cl::Program buildCLProgram(std::string program_src,
104  std::string kernelPath,
105  int nMaxPlanes,
106  int nPlanes,
107  int method,
108  int planeMethod,
109  int nStarts,
110  float brightnessWeight,
111  float newnessWeight);
122  virtual bool reconstruct(ProcessedUSInputDataPtr input,
123  vtkImageDataPtr outputData,
124  float radius,
125  int nClosePlanes);
126 
136  virtual bool initializeFrameBlocks(frameBlock_t* framePointers,
137  int numBlocks,
138  ProcessedUSInputDataPtr inputFrames);
146  virtual void freeFrameBlocks(frameBlock_t* framePointers,
147  int numBlocks);
148 
149 
163  virtual void fillPlaneMatrices(float *planeMatrices,
165 
169  void setProfiling(bool on);
170  double getTotalExecutionTime();
171  double getKernelExecutionTime();
172 
173 private:
174  void setKernelArguments(
175  cl::Kernel kernel,
176  int volume_xsize,
177  int volume_ysize,
178  int volume_zsize,
179  float volume_xspacing,
180  float volume_yspacing,
181  float volume_zspacing,
182  int in_xsize,
183  int in_ysize,
184  float in_xspacing,
185  float in_yspacing,
186  std::vector<cl::Buffer>& blocks,
187  cl::Buffer out_volume,
188  cl::Buffer plane_matrices,
189  cl::Buffer mask,
190  size_t plane_eqs_size,
191  size_t close_planes_size,
192  float radius);
193  size_t calculateSpaceNeededForClosePlanes(cl::Kernel kernel, cl::Device device, size_t local_work_size, size_t nPlanes_numberOfInputImages, int nClosePlanes);
194  bool isUsingTooMuchMemory(size_t outputVolumeSize, size_t inputBlocksLength, cl_ulong globalMemUse);
195  void measureAndExecuteKernel(cl::CommandQueue queue, cl::Kernel kernel, size_t global_work_size, size_t local_work_size, std::string measurementName);
196  void measureAndReadBuffer(cl::CommandQueue queue, cl::Buffer outputBuffer, size_t outputVolumeSize, void *outputData, std::string measurementName);
197 
198  void startProfiling(std::string name, cl::CommandQueue queue);
199  void stopProfiling(std::string name, cl::CommandQueue queue);
200 
201  cl::Kernel mKernel;
202  oul::ContextPtr mOulContex;
203  oul::RuntimeMeasurementsManagerPtr mRuntime;
204  std::set<std::string> mMeasurementNames;
205  std::string mKernelMeasurementName;
206 
207 };
208 
209 typedef boost::shared_ptr<VNNclAlgorithm> VNNclAlgorithmPtr;
210 
211 } /* namespace cx */
212 #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 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
virtual void freeFrameBlocks(frameBlock_t *framePointers, int numBlocks)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
boost::shared_ptr< VNNclAlgorithm > VNNclAlgorithmPtr