[Aqsis-commits] SF.net SVN: aqsis: [1864] branches/texfiltering/aqsis/texturing/texlib
Brought to you by:
ltatkinson,
pgregory
From: <c4...@us...> - 2008-01-23 02:19:33
|
Revision: 1864 http://aqsis.svn.sourceforge.net/aqsis/?rev=1864&view=rev Author: c42f Date: 2008-01-22 18:19:38 -0800 (Tue, 22 Jan 2008) Log Message: ----------- * Make channel selection and default fill values work correctly. - This required small alterations to the SampleAccumulatorConcept, to allow it to deduce the expected sample vector length. - The sample accumulator class also got a new member to store the desired default fill value. Modified Paths: -------------- branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h branches/texfiltering/aqsis/texturing/texlib/sampleaccum.h branches/texfiltering/aqsis/texturing/texlib/texturebuffer.h branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.cpp branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.h Modified: branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/levelsamplercache.h 2008-01-23 02:19:38 UTC (rev 1864) @@ -116,7 +116,7 @@ m_levels[i].reset(new TextureBufferT()); m_texFile->readPixels(*m_levels[i]); } - /// \todo: Init default sampling opts from texture file + m_defaultSampleOptions.fillFromFileHeader(m_texFile->header()); } else { Modified: branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/mipmaptexturesampler.h 2008-01-23 02:19:38 UTC (rev 1864) @@ -100,7 +100,8 @@ // filter the texture. CqSampleAccum<CqEwaFilterWeights> accumulator(weights, - sampleOpts.startChannel(), sampleOpts.numChannels(), outSamps); + sampleOpts.startChannel(), sampleOpts.numChannels(), + outSamps, sampleOpts.fill()); if(level > 0) { Modified: branches/texfiltering/aqsis/texturing/texlib/sampleaccum.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/sampleaccum.h 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/sampleaccum.h 2008-01-23 02:19:38 UTC (rev 1864) @@ -54,7 +54,7 @@ * a.accumulate(x, y, s(x,y)) * end * - * This example illustrates the single method which classes conforming to + * This example illustrates the one of the methods which classes conforming to * SampleAccumulatorConcept must implement: * * template<typename SampleVectorT> @@ -62,6 +62,12 @@ * * SampleVectorT is assumed to be some type which has an indexing operator[] * which returns floating point values. + * + * A further method should also be implemented for the SampleAccumulatorConcept: + * the accumulator needs an efficient way to determine the length of the + * samples, this is provided by the method: + * + * void setSampleVectorLength(TqInt sampleVectorLength); */ /** \brief A class to accumulate weighted sample data during filtering. @@ -87,10 +93,23 @@ * accumulated sample vectors * \param numChans - number of channels in the result * \param resultBuf - float buffer to place the filtered result into. + * \param fill - value to fill nonexistant channels with. */ inline CqSampleAccum(const FilterWeightT& filterWeights, - TqInt startChan, TqInt numChans, TqFloat* resultBuf); + TqInt startChan, TqInt numChans, TqFloat* resultBuf, + TqFloat fill = 0); + /** \brief Set length for sample vectors passed to accumulate(). + * + * In principle, this information could be a part of the inSamples + * parameter to accumulate(), but it's wasteful to have to check such + * information at each invocation of accumulate() when all the sample + * vectors should be the same length. + * + * \param length - the length of the sample vectors passed to accumulate. + */ + inline void setSampleVectorLength(TqInt sampleVectorLength); + /** \brief Accumulate a sample into the output buffer at the given position. * * \param x @@ -106,7 +125,9 @@ const FilterWeightT& m_filterWeights; TqInt m_startChan; TqInt m_numChans; + TqInt m_numChansFill; TqFloat* m_resultBuf; + TqFloat m_fill; TqFloat m_totWeight; }; @@ -119,11 +140,13 @@ template<typename FilterWeightT> inline CqSampleAccum<FilterWeightT>::CqSampleAccum( const FilterWeightT& filterWeights, TqInt startChan, TqInt numChans, - TqFloat* resultBuf) + TqFloat* resultBuf, TqFloat fill) : m_filterWeights(filterWeights), m_startChan(startChan), m_numChans(numChans), + m_numChansFill(0), m_resultBuf(resultBuf), + m_fill(fill), m_totWeight(0) { // Zero the output channel on construction @@ -132,6 +155,31 @@ } template<typename FilterWeightT> +inline void CqSampleAccum<FilterWeightT>::setSampleVectorLength(TqInt sampleVectorLength) +{ + assert(sampleVectorLength > 0); + TqInt totNumChans = m_numChans + m_numChansFill; + if(m_startChan + totNumChans <= sampleVectorLength) + { + // All channels should be filled with sample data + m_numChans = totNumChans; + m_numChansFill = 0; + } + else if(m_startChan >= sampleVectorLength) + { + // All channels should be filled with the "fill" value + m_numChans = 0; + m_numChansFill = totNumChans; + } + else + { + // Some channels get sample data; some get fill values. + m_numChans = sampleVectorLength - m_startChan; + m_numChansFill = totNumChans - m_numChans; + } +} + +template<typename FilterWeightT> template<typename SampleVectorT> inline void CqSampleAccum<FilterWeightT>::accumulate(TqInt x, TqInt y, const SampleVectorT& inSamples) @@ -159,6 +207,9 @@ for(TqInt i = 0; i < m_numChans; ++i) m_resultBuf[i] *= renorm; } + // Fill extra non-sampled channels with the "fill" value. + for(TqInt i = 0; i < m_numChansFill; ++i) + m_resultBuf[i+m_numChans] = m_fill; } } // namespace Aqsis Modified: branches/texfiltering/aqsis/texturing/texlib/texturebuffer.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturebuffer.h 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/texturebuffer.h 2008-01-23 02:19:38 UTC (rev 1864) @@ -303,6 +303,7 @@ const SqFilterSupport& support, EqWrapMode xWrapMode, EqWrapMode yWrapMode) const { + sampleAccum.setSampleVectorLength(m_numChannels); if( support.inRange(0, m_width, 0, m_height) ) { // The bounds for the filter support are all inside the texture; do Modified: branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.cpp =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.cpp 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.cpp 2008-01-23 02:19:38 UTC (rev 1864) @@ -51,9 +51,10 @@ //------------------------------------------------------------------------------ // CqTextureSampleOptions implementation -void CqTextureSampleOptions::fillFromFileHeader(CqTexFileHeader& header) +void CqTextureSampleOptions::fillFromFileHeader(const CqTexFileHeader& header) { - /// \todo implementation + /// \todo Find a way to store & retrieve the downsampling filter? + /// \todo Retreive texture wrap modes } void CqTextureSampleOptions::adjustSampleQuad(SqSampleQuad& quad) const Modified: branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.h =================================================================== --- branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.h 2008-01-22 17:10:10 UTC (rev 1863) +++ branches/texfiltering/aqsis/texturing/texlib/texturesampleoptions.h 2008-01-23 02:19:38 UTC (rev 1864) @@ -141,7 +141,7 @@ /// Set the start channel index where channels will be read from. inline void setStartChannel(TqInt startChannel); /// Set the number of channels to sample - inline void setNumChannels(TqInt numChannels); + inline void setNumChannels(TqInt numChans); /// Set the number of samples used by stochastic sampling methods. inline void setNumSamples(TqInt numSamples); /// Set the wrap mode in both directions @@ -160,7 +160,7 @@ * * \param header - extract options from here. */ - void fillFromFileHeader(CqTexFileHeader& header); + void fillFromFileHeader(const CqTexFileHeader& header); //-------------------------------------------------- /** \brief Adjust a sample quad to take into account the width @@ -198,8 +198,6 @@ TqInt m_startChannel; /// Number of channels to sample from the texture. TqInt m_numChannels; - /// Limit on the number of channels in the associated texture file. - //TqInt m_numChannelsLimit; /// Number of samples to take when using a stochastic sampler TqInt m_numSamples; /// Wrap modes specifying what the sampler should do with (s,t) coordinates @@ -368,10 +366,10 @@ m_startChannel = startChannel; } -inline void CqTextureSampleOptions::setNumChannels(TqInt numChannels) +inline void CqTextureSampleOptions::setNumChannels(TqInt numChans) { - assert(numChannels >= 0); - m_numChannels = numChannels; + assert(numChans >= 0); + m_numChannels = numChans; } inline void CqTextureSampleOptions::setNumSamples(TqInt numSamples) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |