Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShImage3D.cpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #include "ShImage3D.hpp" 00028 #include <string> 00029 #include <cstring> 00030 #include <cstdio> 00031 #include <sstream> 00032 #include "ShException.hpp" 00033 #include "ShError.hpp" 00034 #include "ShDebug.hpp" 00035 00036 namespace SH { 00037 00038 ShImage3D::ShImage3D() 00039 : m_width(0), m_height(0), m_depth(0), m_elements(0), m_memory(0) 00040 { 00041 } 00042 00043 ShImage3D::ShImage3D(int width, int height, int depth, int elements) 00044 : m_width(width), m_height(height), m_depth(depth), m_elements(elements), 00045 m_memory(new ShHostMemory(sizeof(float) * m_width * m_height * m_depth * m_elements)) 00046 { 00047 } 00048 00049 ShImage3D::ShImage3D(const ShImage3D& other) 00050 : m_width(other.m_width), m_height(other.m_height), m_depth(other.m_depth), 00051 m_elements(other.m_elements), 00052 m_memory(other.m_memory ? 00053 new ShHostMemory(sizeof(float) * m_width * m_height * m_depth * m_elements) : 0) 00054 { 00055 if (m_memory) { 00056 std::memcpy(m_memory->hostStorage()->data(), 00057 other.m_memory->hostStorage()->data(), 00058 m_width * m_height * m_depth * m_elements * sizeof(float)); 00059 } 00060 } 00061 00062 ShImage3D::~ShImage3D() 00063 { 00064 } 00065 00066 ShImage3D& ShImage3D::operator=(const ShImage3D& other) 00067 { 00068 m_width = other.m_width; 00069 m_height = other.m_height; 00070 m_depth = other.m_depth; 00071 m_elements = other.m_elements; 00072 m_memory = (other.m_memory ? 00073 new ShHostMemory(sizeof(float) * m_width * m_height * m_depth * m_elements) : 0); 00074 std::memcpy(m_memory->hostStorage()->data(), 00075 other.m_memory->hostStorage()->data(), 00076 m_width * m_height * m_depth * m_elements * sizeof(float)); 00077 00078 return *this; 00079 } 00080 00081 int ShImage3D::width() const 00082 { 00083 return m_width; 00084 } 00085 00086 int ShImage3D::height() const 00087 { 00088 return m_height; 00089 } 00090 00091 int ShImage3D::depth() const 00092 { 00093 return m_depth; 00094 } 00095 00096 int ShImage3D::elements() const 00097 { 00098 return m_elements; 00099 } 00100 00101 float ShImage3D::operator()(int x, int y, int z, int i) const 00102 { 00103 SH_DEBUG_ASSERT(m_memory); 00104 00105 return data()[m_elements * ((m_width * (m_height * z + y) + x)) + i]; 00106 } 00107 00108 float& ShImage3D::operator()(int x, int y, int z, int i) 00109 { 00110 SH_DEBUG_ASSERT(m_memory); 00111 return data()[m_elements * ((m_width * (m_height * z + y) + x)) + i]; 00112 } 00113 00114 const float* ShImage3D::data() const 00115 { 00116 if (!m_memory) return 0; 00117 return reinterpret_cast<const float*>(m_memory->hostStorage()->data()); 00118 } 00119 00120 float* ShImage3D::data() 00121 { 00122 if (!m_memory) return 0; 00123 return reinterpret_cast<float*>(m_memory->hostStorage()->data()); 00124 } 00125 00126 ShMemoryPtr ShImage3D::memory() 00127 { 00128 return m_memory; 00129 } 00130 00131 ShPointer<const ShMemory> ShImage3D::memory() const 00132 { 00133 return m_memory; 00134 } 00135 00136 }

Generated on Mon Oct 18 14:17:39 2004 for Sh by doxygen 1.3.7