28 template<
typename VolumeType >
34 uint8_t volumeWidthPower = 0;
35 uint8_t volumeHeightPower = 0;
36 uint8_t volumeDepthPower = 0;
37 stream.read(reinterpret_cast<char*>(&volumeWidthPower),
sizeof(volumeWidthPower));
38 stream.read(reinterpret_cast<char*>(&volumeHeightPower),
sizeof(volumeHeightPower));
39 stream.read(reinterpret_cast<char*>(&volumeDepthPower),
sizeof(volumeDepthPower));
41 uint16_t volumeWidth = 0x0001 << volumeWidthPower;
42 uint16_t volumeHeight = 0x0001 << volumeHeightPower;
43 uint16_t volumeDepth = 0x0001 << volumeDepthPower;
49 for(uint16_t z = 0; z < volumeDepth; ++z)
54 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
58 for(uint16_t y = 0; y < volumeHeight; ++y)
60 for(uint16_t x = 0; x < volumeWidth; ++x)
62 VolumeType::VoxelType value;
63 stream.read(reinterpret_cast<char*>(&value),
sizeof(value));
65 volume->setVoxelAt(x,y,z,value);
79 template<
typename VolumeType >
85 uint16_t volumeWidth = volume.getWidth();
86 uint16_t volumeHeight = volume.getHeight();
87 uint16_t volumeDepth = volume.getDepth();
89 uint8_t volumeWidthPower =
logBase2(volumeWidth);
90 uint8_t volumeHeightPower =
logBase2(volumeHeight);
91 uint8_t volumeDepthPower =
logBase2(volumeDepth);
93 stream.write(reinterpret_cast<char*>(&volumeWidthPower),
sizeof(volumeWidthPower));
94 stream.write(reinterpret_cast<char*>(&volumeHeightPower),
sizeof(volumeHeightPower));
95 stream.write(reinterpret_cast<char*>(&volumeDepthPower),
sizeof(volumeDepthPower));
98 VolumeType::Sampler volIter(&volume);
99 for(uint16_t z = 0; z < volumeDepth; ++z)
104 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
108 for(uint16_t y = 0; y < volumeHeight; ++y)
110 for(uint16_t x = 0; x < volumeWidth; ++x)
112 volIter.setPosition(x,y,z);
113 VolumeType::VoxelType value = volIter.getVoxel();
114 stream.write(reinterpret_cast<char*>(&value),
sizeof(value));
128 template<
typename VolumeType >
134 uint8_t volumeWidthPower = 0;
135 uint8_t volumeHeightPower = 0;
136 uint8_t volumeDepthPower = 0;
137 stream.read(reinterpret_cast<char*>(&volumeWidthPower),
sizeof(volumeWidthPower));
138 stream.read(reinterpret_cast<char*>(&volumeHeightPower),
sizeof(volumeHeightPower));
139 stream.read(reinterpret_cast<char*>(&volumeDepthPower),
sizeof(volumeDepthPower));
141 uint16_t volumeWidth = 0x0001 << volumeWidthPower;
142 uint16_t volumeHeight = 0x0001 << volumeHeightPower;
143 uint16_t volumeDepth = 0x0001 << volumeDepthPower;
149 bool firstTime =
true;
150 uint32_t runLength = 0;
151 VolumeType::VoxelType value;
152 stream.read(reinterpret_cast<char*>(&value),
sizeof(value));
153 stream.read(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
154 for(uint16_t z = 0; z < volumeDepth; ++z)
159 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
163 for(uint16_t y = 0; y < volumeHeight; ++y)
165 for(uint16_t x = 0; x < volumeWidth; ++x)
169 volume->setVoxelAt(x,y,z,value);
174 stream.read(reinterpret_cast<char*>(&value),
sizeof(value));
175 stream.read(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
177 volume->setVoxelAt(x,y,z,value);
193 template<
typename VolumeType >
199 uint16_t volumeWidth = volume.getWidth();
200 uint16_t volumeHeight = volume.getHeight();
201 uint16_t volumeDepth = volume.getDepth();
203 uint8_t volumeWidthPower =
logBase2(volumeWidth);
204 uint8_t volumeHeightPower =
logBase2(volumeHeight);
205 uint8_t volumeDepthPower =
logBase2(volumeDepth);
207 stream.write(reinterpret_cast<char*>(&volumeWidthPower),
sizeof(volumeWidthPower));
208 stream.write(reinterpret_cast<char*>(&volumeHeightPower),
sizeof(volumeHeightPower));
209 stream.write(reinterpret_cast<char*>(&volumeDepthPower),
sizeof(volumeDepthPower));
212 VolumeType::Sampler volIter(&volume);
213 VolumeType::VoxelType current;
214 uint32_t runLength = 0;
215 bool firstTime =
true;
216 for(uint16_t z = 0; z < volumeDepth; ++z)
221 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
225 for(uint16_t y = 0; y < volumeHeight; ++y)
227 for(uint16_t x = 0; x < volumeWidth; ++x)
229 volIter.setPosition(x,y,z);
230 VolumeType::VoxelType value = volIter.getVoxel();
245 stream.write(reinterpret_cast<char*>(¤t),
sizeof(current));
246 stream.write(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
254 stream.write(reinterpret_cast<char*>(¤t),
sizeof(current));
255 stream.write(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
268 template<
typename VolumeType >
272 stream.read(pIdentifier, 7);
273 pIdentifier[7] =
'\0';
274 if(strcmp(pIdentifier,
"PolyVox") != 0)
280 stream.read(reinterpret_cast<char*>(&uVersion),
sizeof(uVersion));
293 template<
typename VolumeType >
296 char pIdentifier[] =
"PolyVox";
297 stream.write(pIdentifier, 7);
299 uint16_t uVersion = 0;
300 stream.write(reinterpret_cast<const char*>(&uVersion),
sizeof(uVersion));
307 template<
typename VolumeType >
311 uint16_t volumeWidth = 0;
312 uint16_t volumeHeight = 0;
313 uint16_t volumeDepth = 0;
314 stream.read(reinterpret_cast<char*>(&volumeWidth),
sizeof(volumeWidth));
315 stream.read(reinterpret_cast<char*>(&volumeHeight),
sizeof(volumeHeight));
316 stream.read(reinterpret_cast<char*>(&volumeDepth),
sizeof(volumeDepth));
323 bool firstTime =
true;
324 uint32_t runLength = 0;
325 VolumeType::VoxelType value;
326 stream.read(reinterpret_cast<char*>(&value),
sizeof(value));
327 stream.read(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
328 for(uint16_t z = 0; z < volumeDepth; ++z)
333 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
337 for(uint16_t y = 0; y < volumeHeight; ++y)
339 for(uint16_t x = 0; x < volumeWidth; ++x)
343 volume.setVoxelAt(x,y,z,value);
348 stream.read(reinterpret_cast<char*>(&value),
sizeof(value));
349 stream.read(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
351 volume.setVoxelAt(x,y,z,value);
367 template<
typename VolumeType >
371 uint16_t volumeWidth = volume.getWidth();
372 uint16_t volumeHeight = volume.getHeight();
373 uint16_t volumeDepth = volume.getDepth();
375 stream.write(reinterpret_cast<char*>(&volumeWidth),
sizeof(volumeWidth));
376 stream.write(reinterpret_cast<char*>(&volumeHeight),
sizeof(volumeHeight));
377 stream.write(reinterpret_cast<char*>(&volumeDepth),
sizeof(volumeDepth));
380 VolumeType::Sampler volIter(&volume);
381 VolumeType::VoxelType current;
382 uint32_t runLength = 0;
383 bool firstTime =
true;
384 for(uint16_t z = 0; z < volumeDepth; ++z)
389 float fProgress =
static_cast<float>(z) / static_cast<float>(volumeDepth);
393 for(uint16_t y = 0; y < volumeHeight; ++y)
395 for(uint16_t x = 0; x < volumeWidth; ++x)
397 volIter.setPosition(x,y,z);
398 VolumeType::VoxelType value = volIter.getVoxel();
413 stream.write(reinterpret_cast<char*>(¤t),
sizeof(current));
414 stream.write(reinterpret_cast<char*>(&runLength),
sizeof(runLength));
422 stream.write(reinterpret_cast<char*>(¤t),
sizeof(current));
423 stream.write(reinterpret_cast<char*>(&runLength),
sizeof(runLength));