ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CuTexImage.h
Go to the documentation of this file.
1 // File: CuTexImage.h
3 // Author: Changchang Wu
4 // Description : interface for the CuTexImage class.
5 // class for storing data in CUDA.
6 //
7 // Copyright (c) 2011 Changchang Wu (ccwu@cs.washington.edu)
8 // and the University of Washington at Seattle
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public
12 // License as published by the Free Software Foundation; either
13 // Version 3 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
19 //
21 
22 #ifndef CU_TEX_IMAGE_H
23 #define CU_TEX_IMAGE_H
24 
25 #ifndef PBA_NO_GPU
26 #include <cuda_runtime.h>
27 #endif
28 
29 namespace pba {
30 
31 class CuTexImage {
32  protected:
33  bool _owner;
34  void* _cuData;
35  unsigned int _numChannel;
36  unsigned int _imgWidth;
37  unsigned int _imgHeight;
38  size_t _numBytes;
39 
40  public:
41  bool InitTexture(unsigned int width, unsigned int height,
42  unsigned int nchannel = 1);
43  void SetTexture(void* data, unsigned int width, unsigned int nchannel = 1);
44 
45  void SwapData(CuTexImage& src);
46  void CopyToHost(void* buf);
47  void CopyFromDevice(const void* buf);
48  void CopyFromHost(const void* buf);
49  void SaveToFile(const char* name);
50  void ReleaseData();
51 
52  public:
53  inline float* data() { return GetRequiredSize() ? ((float*)_cuData) : NULL; }
54  inline bool IsValid() { return _cuData != NULL && GetDataSize() > 0; }
55  inline unsigned int GetLength() {
56  return _imgWidth * _imgHeight * _numChannel;
57  }
58  inline unsigned int GetImgWidth() { return _imgWidth; }
59  inline unsigned int GetImgHeight() { return _imgHeight; }
60  inline size_t GetReservedWidth() {
61  return _numBytes == 0
62  ? 0
63  : (_numBytes / (_imgHeight * _numChannel * sizeof(float)));
64  }
65  inline size_t GetDataSize() { return _numBytes == 0 ? 0 : GetRequiredSize(); }
66  inline size_t GetRequiredSize() {
67  return sizeof(float) * _imgWidth * _imgHeight * _numChannel;
68  }
69  inline unsigned int IsHugeData() { return (GetLength() - 1) / (1 << 27); }
70 
71  public:
72  CuTexImage();
73  virtual ~CuTexImage();
74 };
75 
76 } // namespace pba
77 
78 #endif // !defined(CU_TEX_IMAGE_H)
int width
std::string name
int height
#define NULL
void CopyFromHost(const void *buf)
Definition: CuTexImage.cpp:109
size_t GetReservedWidth()
Definition: CuTexImage.h:60
void SwapData(CuTexImage &src)
Definition: CuTexImage.cpp:55
unsigned int GetLength()
Definition: CuTexImage.h:55
void ReleaseData()
Definition: CuTexImage.cpp:49
void CopyFromDevice(const void *buf)
Definition: CuTexImage.cpp:115
unsigned int _imgHeight
Definition: CuTexImage.h:37
void CopyToHost(void *buf)
Definition: CuTexImage.cpp:122
virtual ~CuTexImage()
Definition: CuTexImage.cpp:45
void * _cuData
Definition: CuTexImage.h:34
float * data()
Definition: CuTexImage.h:53
bool InitTexture(unsigned int width, unsigned int height, unsigned int nchannel=1)
Definition: CuTexImage.cpp:80
bool IsValid()
Definition: CuTexImage.h:54
unsigned int _imgWidth
Definition: CuTexImage.h:36
unsigned int IsHugeData()
Definition: CuTexImage.h:69
unsigned int GetImgHeight()
Definition: CuTexImage.h:59
size_t GetRequiredSize()
Definition: CuTexImage.h:66
size_t GetDataSize()
Definition: CuTexImage.h:65
size_t _numBytes
Definition: CuTexImage.h:38
unsigned int _numChannel
Definition: CuTexImage.h:35
void SaveToFile(const char *name)
Definition: CuTexImage.cpp:132
void SetTexture(void *data, unsigned int width, unsigned int nchannel=1)
Definition: CuTexImage.cpp:98
unsigned int GetImgWidth()
Definition: CuTexImage.h:58
Definition: ConfigBA.cpp:44