00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }