CqShadowSampler::CqShadowSampler(const boost::shared_ptr<IqTiledTexInputFile>& file, const CqMatrix& currToWorld) : m_currToLight(), m_currToTexture(), m_pixelBuf(), m_defaultSampleOptions() { if(!file) AQSIS_THROW_XQERROR(XqInternal, EqE_NoFile, "Cannot construct shadow map from NULL file handle"); const CqTexFileHeader& header = file->header(); if(header.channelList().sharedChannelType() != Channel_Float32) AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "Shadow maps must hold 32-bit floating point data"); // Get matrix which transforms the sample points to the light camera coordinates. const CqMatrix* worldToLight = header.findPtr<Attr::WorldToCameraMatrix>(); if(!worldToLight) { AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "No world -> camera matrix found in file \"" << file->fileName() << "\""); } m_currToLight = (*worldToLight) * currToWorld; // Get matrix which transforms the sample points to raster texture coordinates. const CqMatrix* worldToLightScreen = header.findPtr<Attr::WorldToScreenMatrix>(); if(!worldToLightScreen) { AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "No world -> screen matrix found in file \"" << file->fileName() << "\""); } m_currToTexture = (*worldToLightScreen) * currToWorld; // worldToLightScreen transforms world coordinates to "screen" coordinates, // ie, onto the 2D box [-1,1]x[-1,1]. We instead want texture coordinates, // which correspond to the box [0,1]x[0,1]. In addition, the direction of // increase of the y-axis should be swapped, since texture coordinates // define the origin to be in the top left of the texture rather than the // bottom right. m_currToTexture.Translate(CqVector3D(1,-1,0)); m_currToTexture.Scale(0.5f, -0.5f, 1); m_defaultSampleOptions.fillFromFileHeader(header); // Connect pixel array to file m_pixelBuf.reset(new CqTileArray<TqFloat>(file, 0)); }
void CqMixedImageBuffer::copyFrom(const CqMixedImageBuffer& source, TqInt topLeftX, TqInt topLeftY) { if(source.m_channelList.numChannels() != m_channelList.numChannels()) AQSIS_THROW_XQERROR(XqInternal, EqE_Limit, "Number of source and destination channels do not match"); // compute size and top left coords of region to copy. TqInt copyWidth = 0; TqInt destTopLeftX = 0; TqInt srcTopLeftX = 0; getCopyRegionSize(topLeftX, source.m_width, m_width, srcTopLeftX, destTopLeftX, copyWidth); TqInt copyHeight = 0; TqInt destTopLeftY = 0; TqInt srcTopLeftY = 0; getCopyRegionSize(topLeftY, source.m_height, m_height, srcTopLeftY, destTopLeftY, copyHeight); // return if no overlap if(copyWidth <= 0 || copyHeight <= 0) return; for(TqInt i = 0; i < m_channelList.numChannels(); ++i) { channel(i, destTopLeftX, destTopLeftY, copyWidth, copyHeight) ->copyFrom(*source.channel(i, srcTopLeftX, srcTopLeftY, copyWidth, copyHeight)); } }
CqRibInputBuffer::CqRibInputBuffer(std::istream& inStream, const std::string& streamName) : m_inStream(&inStream), m_streamName(streamName), m_gzipStream(), m_bufPos(1), m_bufEnd(2), m_currPos(1,0), m_prevPos(-1,-1) { // Zero the putback chars m_buffer[0] = 0; m_buffer[1] = 0; if(isGzippedStream(inStream)) { # ifdef USE_GZIPPED_RIB // Initialise gzip decompressor namespace io = boost::iostreams; io::filtering_stream<io::input>* zipStream = 0; m_gzipStream.reset(zipStream = new io::filtering_stream<io::input>()); zipStream->push(io::gzip_decompressor()); zipStream->push(inStream); m_inStream = m_gzipStream.get(); # else AQSIS_THROW_XQERROR(XqParseError, EqE_Unimplement, "gzipped RIB detected, but aqsis compiled without gzip support."); # endif // USE_GZIPPED_RIB } }
boost::shared_ptr<CqImageChannel> CqMixedImageBuffer::channelImpl(TqInt index, TqInt topLeftX, TqInt topLeftY, TqInt width, TqInt height) const { if(width == 0) width = m_width; if(height == 0) height = m_height; assert(topLeftX + width <= m_width); assert(topLeftY + height <= m_height); TqInt stride = m_channelList.bytesPerPixel(); // Start offset for the channel TqUint8* startPtr = m_data.get() + (topLeftY*m_width + topLeftX)*stride + m_channelList.channelByteOffset(index); TqInt rowSkip = m_width - width; switch(m_channelList[index].type) { case Channel_Float32: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqFloat>(m_channelList[index], startPtr, width, height, stride, rowSkip)); case Channel_Unsigned32: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqUint32>(m_channelList[index], startPtr, width, height, stride, rowSkip)); case Channel_Signed32: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqInt32>(m_channelList[index], startPtr, width, height, stride, rowSkip)); # ifdef USE_OPENEXR case Channel_Float16: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<half>(m_channelList[index], startPtr, width, height, stride, rowSkip)); # endif case Channel_Unsigned16: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqUint16>(m_channelList[index], startPtr, width, height, stride, rowSkip)); case Channel_Signed16: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqInt16>(m_channelList[index], startPtr, width, height, stride, rowSkip)); case Channel_Signed8: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqInt8>(m_channelList[index], startPtr, width, height, stride, rowSkip)); case Channel_Unsigned8: return boost::shared_ptr<CqImageChannel>( new CqImageChannelTyped<TqUint8>(m_channelList[index], startPtr, width, height, stride, rowSkip)); default: AQSIS_THROW_XQERROR(XqInternal, EqE_Bug, "Unknown channel type"); } }
void CqTiffOutputFile::writePixelsImpl(const CqMixedImageBuffer& buffer) { if(!buffer.channelList().channelTypesMatch(m_header.channelList())) { AQSIS_THROW_XQERROR(XqInternal, EqE_Bug, "Buffer and file channels don't match"); } if(m_header.findPtr<Attr::TileInfo>()) writeTiledPixels(buffer); else writeScanlinePixels(buffer); }
boostfs::path findFile(const std::string& fileName, const std::string& searchPath) { boostfs::path loc = findFileNothrow(fileName, searchPath); if(loc.empty()) { AQSIS_THROW_XQERROR(XqInvalidFile, EqE_NoFile, "Could not find file \"" << fileName << "\" in path: \"" << searchPath << "\""); } return loc; }
boost::shared_ptr<IqTexInputFile> IqTexInputFile::open(const boostfs::path& fileName) { boost::shared_ptr<IqTexInputFile> file = openInputFile(guessFileType(fileName), fileName); if(file) return file; else AQSIS_THROW_XQERROR(XqInvalidFile, EqE_BadFile, "Unknown file type for \"" << fileName << "\""); assert(0); return boost::shared_ptr<IqTexInputFile>(); }
boost::shared_ptr<IqTiledTexInputFile> IqTiledTexInputFile::open( const boostfs::path& fileName) { EqImageFileType type = guessFileType(fileName); switch(type) { case ImageFile_Tiff: return boost::shared_ptr<IqTiledTexInputFile>(new CqTiledTiffInputFile(fileName)); case ImageFile_Unknown: AQSIS_THROW_XQERROR(XqInvalidFile, EqE_BadFile, "File \"" << fileName << "\" is not a recognised image type"); break; default: AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "Cannot open file \"" << fileName << "\" of type " << type << " for tiled image I/O"); break; } assert(0); return boost::shared_ptr<IqTiledTexInputFile>(); }
// Dump a 3d vector void CqMPDump::dumpVec3(const CqVector3D& v) { TqFloat x = v.x(); TqFloat y = v.y(); TqFloat z = v.z(); size_t len_written = fwrite((void*)&x, sizeof(TqFloat), 1, m_outFile); len_written += fwrite((void*)&y, sizeof(TqFloat), 1, m_outFile); len_written += fwrite((void*)&z, sizeof(TqFloat), 1, m_outFile); if(len_written != 3) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); }
// Dump a color void CqMPDump::dumpCol(const CqColor& c) { TqFloat r = c.r(); TqFloat g = c.g(); TqFloat b = c.b(); size_t len_written = fwrite((void*)&r, sizeof(TqFloat), 1, m_outFile); len_written += fwrite((void*)&g, sizeof(TqFloat), 1, m_outFile); len_written += fwrite((void*)&b, sizeof(TqFloat), 1, m_outFile); if(len_written != 3) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); }
CqZInputFile::CqZInputFile(const boostfs::path& fileName) : m_header(), m_fileName(fileName), m_fileStream(fileName.c_str(), std::ios::in | std::ios::binary), m_dataBegin(0) { if(!m_fileStream.is_open()) { AQSIS_THROW_XQERROR(XqInvalidFile, EqE_NoFile, "Could not open z-file \"" << fileName << "\" for reading"); } readHeader(m_fileStream, m_header); m_dataBegin = m_fileStream.tellg(); }
/// Get the aqsistex channel type corresponding to an OpenEXR channel type EqChannelType channelTypeFromExr(Imf::PixelType exrType) { switch(exrType) { case Imf::UINT: return Channel_Unsigned32; case Imf::FLOAT: return Channel_Float32; case Imf::HALF: return Channel_Float16; default: AQSIS_THROW_XQERROR(XqInternal, EqE_Bug, "Unknown OpenEXR pixel type"); } }
CqExrInputFile::CqExrInputFile(const boostfs::path& fileName) : m_header(), m_exrFile() { try { m_exrFile.reset(new Imf::InputFile(fileName.file_string().c_str())); } catch(Iex::BaseExc &e) { AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, e.what()); } convertHeader(m_exrFile->header(), m_header); }
//------------------------------------------------------------------------------ // IqTexOutputFile implementation boost::shared_ptr<IqTexOutputFile> IqTexOutputFile::open( const boostfs::path& fileName, EqImageFileType fileType, const CqTexFileHeader& header) { // Check some of the header data to make sure it's minimally sane... if(header.width() <= 0 || header.height() <= 0) { AQSIS_THROW_XQERROR(XqInternal, EqE_BadFile, "Cannot open \"" << fileName << "\" - image width and height cannot be negative or zero."); } if(header.channelList().numChannels() == 0) { AQSIS_THROW_XQERROR(XqInternal, EqE_BadFile, "Cannot open \"" << fileName << "\" - no data channels present."); } // Create the new file object boost::shared_ptr<IqTexOutputFile> newFile = openMultiOutputFile(fileName, fileType, header); if(newFile) return newFile; switch(fileType) { // case ...: // Add new output formats here! case ImageFile_Exr: case ImageFile_Jpg: case ImageFile_Png: AQSIS_THROW_XQERROR(XqInternal, EqE_Unimplement, "Cannot open \"" << fileName << "\" - unimplemented file type \"" << fileType << "\""); default: AQSIS_THROW_XQERROR(XqInternal, EqE_BadFile, "Cannot open \"" << fileName << "\" - unknown file type \"" << fileType << "\""); } return newFile; }
RibLexer::FloatArray RibLexerImpl::getFloatArray(int length) { std::vector<float>& buf = m_floatArrayPool.getBuf(); if(m_tokenizer.peek().type() == RibToken::ARRAY_BEGIN) { // Read an array in [ num1 num2 ... num_n ] format m_tokenizer.get(); // consume '[' bool parsing = true; while(parsing) { const RibToken& tok = m_tokenizer.get(); switch(tok.type()) { case RibToken::INTEGER: buf.push_back(tok.intVal()); break; case RibToken::FLOAT: buf.push_back(tok.floatVal()); break; case RibToken::ARRAY_END: parsing = false; break; default: tokenError("float array element", tok); break; } } if(length >= 0 && static_cast<int>(buf.size()) != length) { AQSIS_THROW_XQERROR(XqParseError, EqE_Syntax, "expected " << length << " float array componenets, got " << buf.size()); } } else if(length >= 0) { // Read an array in num1 num2 ... num_n format (ie, without the usual // array delimiters). for(int i = 0; i < length; ++i) buf.push_back(getFloat()); } else { tokenError("float array", m_tokenizer.get()); } return toRiArray(buf); }
boost::shared_ptr<IqTextureSampler> IqTextureSampler::create( const boost::shared_ptr<IqTiledTexInputFile>& file) { assert(file); // Check the texture format and complain if it's not a plain texture const CqTexFileHeader& header = file->header(); switch(header.find<Attr::TextureFormat>(TextureFormat_Unknown)) { case TextureFormat_CubeEnvironment: case TextureFormat_LatLongEnvironment: Aqsis::log() << warning << "Accessing an environment map as a plain texture\n"; break; case TextureFormat_Shadow: Aqsis::log() << warning << "Accessing a shadow map as a plain texture\n"; break; default: // no warnings in generic case. break; } // Create a texture sampler based on the underlying pixel type. switch(header.channelList().sharedChannelType()) { case Channel_Float32: return createMipmapSampler<TqFloat>(file); case Channel_Unsigned32: return createMipmapSampler<TqUint32>(file); case Channel_Signed32: return createMipmapSampler<TqInt32>(file); case Channel_Float16: # ifdef USE_OPENEXR return createMipmapSampler<half>(file); # endif break; case Channel_Unsigned16: return createMipmapSampler<TqUint16>(file); case Channel_Signed16: return createMipmapSampler<TqInt16>(file); case Channel_Unsigned8: return createMipmapSampler<TqUint8>(file); case Channel_Signed8: return createMipmapSampler<TqInt8>(file); default: case Channel_TypeUnknown: break; } AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "Could not create a texture sampler for file \"" << file->fileName() << "\""); return createDummy(); }
Imf::PixelType exrChannelType(EqChannelType type) { switch(type) { case Channel_Unsigned32: return Imf::UINT; case Channel_Float32: return Imf::FLOAT; case Channel_Float16: return Imf::HALF; default: AQSIS_THROW_XQERROR(XqInternal, EqE_Bug, "Unsupported output pixel type for OpenEXR"); } }
CqPrimvarToken::CqPrimvarToken(const char* typeToken, const char* name) : m_class(class_invalid), m_type(type_invalid), m_count(1), m_name() { assert(typeToken != 0); const char* beginName = 0; Ri::TypeSpec spec = parseDeclaration(typeToken, &beginName); if(beginName) AQSIS_THROW_XQERROR(XqParseError, EqE_BadToken, "invalid token: unexpected name \"" << beginName << "\" in type string \"" << typeToken << "\""); m_name = name; typeSpecToEqTypes(&m_class, &m_type, spec); m_count = spec.arraySize; }
//------------------------------------------------------------------------------ // IqMultiTexOutputFile implementation boost::shared_ptr<IqMultiTexOutputFile> IqMultiTexOutputFile::open( const boostfs::path& fileName, EqImageFileType fileType, const CqTexFileHeader& header) { boost::shared_ptr<IqMultiTexOutputFile> newFile = openMultiOutputFile(fileName, fileType, header); if(newFile) { return newFile; } else { AQSIS_THROW_XQERROR(XqInternal, EqE_Incapable, "Cannot open \"" << fileName << "\" - file type \"" << fileType << "\"" << " doesn't support multiple subimages"); } }
void CqTiffOutputFile::writeTiledPixels(const CqMixedImageBuffer& buffer) { SqTileInfo tileInfo = m_header.find<Attr::TileInfo>(); // Check that the buffer has a height that is a multiple of the tile height. if( buffer.height() % tileInfo.height != 0 && m_currentLine + buffer.height() != m_header.height() ) { AQSIS_THROW_XQERROR(XqInternal, EqE_Bug, "pixel buffer with height = " << buffer.height() << " must be a multiple " "of requested tile height (= " << tileInfo.height << ") or run exactly to " "the full image height (= " << m_header.height() << ")."); } CqTiffDirHandle dirHandle(m_fileHandle); const TqUint8* rawBuf = buffer.rawData(); const TqInt bytesPerPixel = buffer.channelList().bytesPerPixel(); boost::scoped_array<TqUint8> tileBuf( new TqUint8[bytesPerPixel*tileInfo.width*tileInfo.height]); const TqInt rowStride = bytesPerPixel*buffer.width(); const TqInt tileRowStride = bytesPerPixel*tileInfo.width; const TqInt endLine = m_currentLine + buffer.height(); const TqInt numTileCols = (buffer.width()-1)/tileInfo.width + 1; for(TqInt line = m_currentLine; line < endLine; line += tileInfo.height) { // srcBuf will point to the beginning of the memory region which will // become the tile. const TqUint8* srcBuf = rawBuf; for(TqInt tileCol = 0; tileCol < numTileCols; ++tileCol) { const TqInt tileDataLen = min(tileRowStride, rowStride - tileCol*tileRowStride); const TqInt tileDataHeight = min(tileInfo.height, buffer.height() - line); // Copy parts of the scanlines into the tile buffer. stridedCopy(tileBuf.get(), tileRowStride, srcBuf, rowStride, tileDataHeight, tileDataLen); TIFFWriteTile(dirHandle.tiffPtr(), reinterpret_cast<tdata_t>(const_cast<TqUint8*>(tileBuf.get())), tileCol*tileInfo.width, line, 0, 0); srcBuf += tileRowStride; } rawBuf += rowStride*tileInfo.height; } m_currentLine = endLine; }
boost::shared_ptr<IqMultiTexInputFile> IqMultiTexInputFile::open( const boostfs::path& fileName) { EqImageFileType type = guessFileType(fileName); boost::shared_ptr<IqMultiTexInputFile> file = openMultiInputFile(type, fileName); if(file) return file; else { AQSIS_THROW_XQERROR(XqInvalidFile, EqE_BadFile, "File \"" << fileName << "\" of type " << type << " doesn't support " "multiple subimages."); } assert(0); return boost::shared_ptr<IqMultiTexInputFile>(); }
// Open the dump file void CqMPDump::open() { char filename[20] = "mpdump.mp"; int sf = sizeof(TqFloat); close(); m_mpcount = 0; m_outFile = fopen(filename, "wb"); if (m_outFile!=NULL) { Aqsis::log() << info << "Creating '" << filename << "'" << std::endl; size_t len_written = fwrite((void*)&sf, sizeof(int), 1, m_outFile); if(len_written != 1) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); } else Aqsis::log() << error << "Could not create '" << filename << "'" << std::endl; }
// Dump global information about the image void CqMPDump::dumpImageInfo() { short id = 3; if (m_outFile==NULL) { Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl; return; } int width = QGetRenderContext() ->poptCurrent()->GetIntegerOption( "System", "Resolution" ) [ 0 ]; int height = QGetRenderContext() ->poptCurrent()->GetIntegerOption( "System", "Resolution" ) [ 1 ]; size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile); len_written += fwrite((void*)&width, sizeof(int), 1, m_outFile); len_written += fwrite((void*)&height, sizeof(int), 1, m_outFile); if(len_written != 3) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); }
void CqImage::prepareImageBuffers(const CqChannelList& channelList) { boost::mutex::scoped_lock lock(mutex()); if(channelList.numChannels() == 0) AQSIS_THROW_XQERROR(XqInternal, EqE_MissingData, "Not enough image channels to display"); // Set up buffer for holding the full-precision data m_realData = boost::shared_ptr<CqMixedImageBuffer>( new CqMixedImageBuffer(channelList, m_imageWidth, m_imageHeight)); fixupDisplayMap(channelList); // Set up 8-bit per pixel display image buffer m_displayData = boost::shared_ptr<CqMixedImageBuffer>( new CqMixedImageBuffer(CqChannelList::displayChannels(), m_imageWidth, m_imageHeight)); m_displayData->initToCheckerboard(); }
/** \brief Throw an error from encountering an unexpected token. * * An error string is generated with the form: * * expected <expected> before <token_description> * * where <expected> is a string describing the expected token and * <token_description> is generated from the bad token provided. * * \param expected - string describing the expected token * \param badTok - the problematic token which was actually obtained. */ void RibLexerImpl::tokenError(const char* expected, const RibToken& badTok) { std::ostringstream msg; msg << "expected " << expected << " before "; switch(badTok.type()) { case RibToken::ARRAY_BEGIN: msg << "'['"; break; case RibToken::ARRAY_END: msg << "']'"; break; case RibToken::ENDOFFILE: msg << "end of file"; // Put ENDOFFILE back into the input, since not doing so may cause // problems for streams which only provide a single ENDOFFILE // token before blocking (eg, ProcRunProgram pipes). m_tokenizer.unget(); break; case RibToken::INTEGER: msg << "integer [= " << badTok.intVal() << "]"; break; case RibToken::FLOAT: msg << "float [= " << badTok.floatVal() << "]"; break; case RibToken::STRING: msg << "string [= \"" << badTok.stringVal() << "\"]"; break; case RibToken::REQUEST: msg << "request [= " << badTok.stringVal() << "]"; // For unexpected REQUEST tokens we back up by one token so that // the next call to nextRequest() can start afresh with the // new request. m_tokenizer.unget(); break; case RibToken::ERROR: msg << "bad token [" << badTok.stringVal() << "]"; break; } AQSIS_THROW_XQERROR(XqParseError, EqE_Syntax, msg.str()); }
void CqTiffOutputFile::initialize() { // make sure all channels are the same type. if(m_header.channelList().sharedChannelType() == Channel_TypeUnknown) AQSIS_THROW_XQERROR(XqInternal, EqE_Limit, "tiff cannot store multiple pixel types in the same image"); // Use lzw compression if the compression hasn't been specified. if(!m_header.findPtr<Attr::Compression>()) m_header.set<Attr::Compression>("lzw"); // Timestamp the file. m_header.setTimestamp(); /// \todo more checking & validation of the header. // Now load the initial settings into the TIFF. CqTiffDirHandle dirHandle(m_fileHandle); dirHandle.writeHeader(m_header); }
void CqIntWrapper::setData(TqInt data) { // As documented in the interface, this class only holds values >= minValue // Use exceptions to indicate failure conditions. if (data < minValue) { AQSIS_THROW_XQERROR(XqException, EqE_Bug, "requested data = " << data << "smaller than minimum value = " << minValue); } // If runtime performance is critical (for example, in an inline function), // consider using assert(). Assert signifies not only that an error // condition shouldn't happen, but that we don't want to even attempt to // recover. // assert(data >= minValue); // Use constants when you know a quantity cannot change. Anything to help // the compiler catch errors at compile-time is a "good thing". const TqInt theAnswer = 42; if(*m_data == theAnswer && data != theAnswer) { // Avoid using unsigned integers, even for things which logically // cannot be negative. Many experts (though perhaps not all) agree // that this is a bad thing in C and C++ because of the subtle bugs it // can cause. For example, the following is false on most // architectures: // // (int)(-1) < (unsigned int)(1) // // For more information, see the aqsis mailing list post: // 'Unsigned integers "considered harmful"?' // http://sourceforge.net/mailarchive/forum.php?thread_name=20070829120534.GA17365%40physics.uq.edu.au&forum_name=aqsis-development const TqInt maxInsults = 10; for(TqInt i = 0; i < maxInsults; ++i) std::cout << "You idiot! You're overriding the answer.\n"; } *m_data = data; }
// Dump a pixel sample void CqMPDump::dump(int x, int y, int idx, const CqVector2D& pos) { short id = 2; TqFloat f; if (m_outFile==NULL) { Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl; return; } size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile); len_written += fwrite((void*)&x, sizeof(int), 1, m_outFile); len_written += fwrite((void*)&y, sizeof(int), 1, m_outFile); len_written += fwrite((void*)&idx, sizeof(int), 1, m_outFile); f = pos.x(); len_written += fwrite((void*)&f, sizeof(TqFloat), 1, m_outFile); f = pos.y(); len_written += fwrite((void*)&f, sizeof(TqFloat), 1, m_outFile); if(len_written != 6) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); }
// Dump a micro polygon void CqMPDump::dump(const CqMicroPolygon& mp) { CqColor c; short id = 1; if (m_outFile==NULL) { Aqsis::log() << error << "Attempted to write to unopened mpdump file." << std::endl; return; } m_mpcount++; size_t len_written = fwrite((void*)&id, sizeof(short), 1, m_outFile); if(len_written != 1) AQSIS_THROW_XQERROR(XqInvalidFile, EqE_System, "Error writing mpdump file"); // Dump vertices in a funny circular order for backward-compatibility // rather than in the usual bilinear patch type order. CqVector3D P[4]; mp.GetVertices(P); dumpVec3(P[0]); dumpVec3(P[1]); dumpVec3(P[3]); dumpVec3(P[2]); if (mp.pGrid()->pVar(EnvVars_Ci)!=NULL) c = *mp.colColor(); else c = CqColor(0.9,0.9,1); dumpCol(c); if (mp.pGrid()->pVar(EnvVars_Oi)!=NULL) c = *mp.colOpacity(); else c = CqColor(0.9,0.9,1); dumpCol(c); }
boost::shared_ptr<IqEnvironmentSampler> IqEnvironmentSampler::create( const boost::shared_ptr<IqTiledTexInputFile>& file) { assert(file); // Create an environment sampler based on the underlying pixel type. switch(file->header().channelList().sharedChannelType()) { case Channel_Float32: return createEnvSampler<TqFloat>(file); case Channel_Unsigned32: return createEnvSampler<TqUint32>(file); case Channel_Signed32: return createEnvSampler<TqInt32>(file); case Channel_Float16: # ifdef USE_OPENEXR return createEnvSampler<half>(file); # endif break; case Channel_Unsigned16: return createEnvSampler<TqUint16>(file); case Channel_Signed16: return createEnvSampler<TqInt16>(file); case Channel_Unsigned8: return createEnvSampler<TqUint8>(file); case Channel_Signed8: return createEnvSampler<TqInt8>(file); default: case Channel_TypeUnknown: break; } AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile, "Could not create an environment sampler for file \"" << file->fileName() << "\""); return createDummy(); }