void testPackHalf() { glam::vec2 vf1(10.0f, -0.125f); unsigned int p1 = glam::packHalf2x16(vf1); TS_ASSERT_EQUALS(p1, 0xb0004900); unsigned int p2 = 0xb0004900; glam::vec2 vf2 = glam::unpackHalf2x16(p2); TS_ASSERT_DELTA(vf2[0], 10.0f, 1e-4); TS_ASSERT_DELTA(vf2[1], -0.125f, 1e-4); glam::vec2 vf3(768.0f, 5.779e-41f); unsigned int p3 = glam::packHalf2x16(vf3); TS_ASSERT_EQUALS(p3, 0x00056200); unsigned int p4 = 0x00056200; glam::vec2 vf4 = glam::unpackHalf2x16(p4); TS_ASSERT_DELTA(vf4[0], 768.0f, 1e-4); TS_ASSERT_DELTA(vf4[1], 5.779e-41f, 1e-4); glam::vec2 vf5(-INFINITY, NAN); unsigned int p5 = glam::packHalf2x16(vf5); TS_ASSERT((p5 & 0xffff) == 0xfc00 && (p5 & 0x7c000000) == 0x7c000000 && (p5 & 0x03ff0000) != 0x00000000); unsigned int p6 = 0x7e00fc00; glam::vec2 vf6 = glam::unpackHalf2x16(p6); #ifndef GLAM_HAS_BROKEN_ISINF // this will fail with -ffast-math, according to http://stackoverflow.com/questions/22931147/22931368#22931368 TS_ASSERT(std::isinf(vf6[0]) && std::signbit(vf6[0]) && std::isnan(vf6[1])); #else TS_ASSERT(*(uint32_t *) &vf6[0] == 0xff800000 && *(uint32_t *) &vf6[1] == 0x7fc00000); #endif for (int i = 0; i <= 15; i++) { glam::vec2 vfi(glam::pow(1.5f, float(i)), glam::pow(2.0f, -float(i))); unsigned int pi = glam::packHalf2x16(vfi); glam::vec2 vfj = glam::unpackHalf2x16(pi); TS_ASSERT_DELTA(vfi[0], vfj[0], 1e0); TS_ASSERT_DELTA(vfi[1], vfj[1], 1e-4); } }
// ------------------------------- // VolumeFile_IO::writeBoundingBox // ------------------------------- // Purpose: // Writes the specified bounding box to the file. The default implementation is slow // because it has to read the entire file. This can be sped up on an individual file type // basis. // ---- Change History ---- // 04/06/2012 -- Joe R. -- Initial implementation. void VolumeFile_IO::writeBoundingBox(const BoundingBox& bbox, const std::string& filename) const { std::vector<Volume> vols; VolumeFileInfo vfi(filename); vfi.boundingBox(bbox); VolMagick::readVolumeFile(vols,filename); BOOST_FOREACH(Volume& vol, vols) vol.boundingBox(bbox); VolMagick::createVolumeFile(filename,vfi); //TODO: don't overwrite existing file until temp file write is complete VolMagick::writeVolumeFile(vols,filename); }
void VolumeGridRoverMainWindow::fileOpen() { QString filename = QFileDialog::getOpenFileName(QString::null, "Volume Files (*.rawiv *.rawv *.cvc *.mrc)", this, "open file dialog", "Choose a volume file" ); if(filename == QString::null) return; functionChangedSlot(); /* set the current transfer function so the slice appears correct */ #if 0 if(filename.endsWith(".rawiv",false)) { m_MappedVolumeFile = new MappedRawIVFile(filename.ascii(),true,true); if(!m_MappedVolumeFile->isValid()) cvcapp.log(5, boost::str(boost::format("VolumeFile::VolumeFile(): Could not load '%s'")%filename.ascii())); } else if(filename.endsWith(".rawv",false)) { m_MappedVolumeFile = new MappedRawVFile(filename.ascii(),true,true); if(!m_MappedVolumeFile->isValid()) cvcapp.log(5, boost::str(boost::format("VolumeFile::VolumeFile(): Could not load '%s'")%filename.ascii())); } else /* try to figure out the volume type */ { m_MappedVolumeFile = new MappedRawIVFile(filename.ascii(),true,false); if(m_MappedVolumeFile->isValid()) return; delete m_MappedVolumeFile; m_MappedVolumeFile = new MappedRawVFile(filename.ascii(),true,false); if(m_MappedVolumeFile->isValid()) return; delete m_MappedVolumeFile; m_MappedVolumeFile = NULL; cvcapp.log(5, "VolumeFile::VolumeFile(): m_MappedVolumeFile == NULL"); } if(m_VolumeGridRover->setVolume(m_MappedVolumeFile)) { functionChangedSlot(); setCaption(filename + " - Volume Grid Rover"); } else setCaption("Volume Grid Rover"); #endif VolMagick::VolumeFileInfo vfi(filename.ascii()); m_VolumeFileInfo = vfi; m_VolumeGridRover->setVolume(vfi); setCaption(filename + " - Volume Grid Rover"); }