DissolveSampleGenerator.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file DissolveSampleGenerator.h 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Fall 2008 00005 00006 @brief 00007 Cool dissolve effect which generates point samples uniformly over a 00008 given 2D domain. The order in which the samples are generated looks random, 00009 but it is actually quite deterministic and guaranteed to "visit" every 00010 bucket in the domain. 00011 <!-------------------------------------------------------------------->**/ 00012 00013 #include "DissolveSampleGenerator.h" 00014 #include <QtCore> 00015 00016 template <class SG> 00017 void DissolveSG<SG>::generate(PointSampleList &outSamples, 00018 const Viewport &viewport) 00019 { 00020 #if 0 00021 const unsigned width = viewport.getWidth(); 00022 const unsigned height = viewport.getHeight(); 00023 00024 const real_t binWidth = viewport.getInvWidth(); 00025 const real_t binHeight = viewport.getInvHeight(); 00026 const unsigned size = width * height; 00027 00028 unsigned randMasks[sizeof(int)]; 00029 for(unsigned i = sizeof(int); i--;) 00030 randMasks[i] = (3 << i); 00031 00032 const unsigned mask = randMasks[_getBitWidth(width * height - 1)]; 00033 unsigned seq = 1; 00034 00035 SG::_addSample(PointSample(0, 0), outSamples); 00036 unsigned count = 1; 00037 00038 do { 00039 const real_t y = 0 + (seq / width); 00040 const real_t x = 0 + (seq % width); 00041 00042 SG::_addSample(PointSample(x, y), outSamples); 00043 ++count; 00044 00045 do { 00046 if (seq & 1) 00047 seq = (seq >> 1) ^ mask; 00048 else seq >>= 1; 00049 } while(seq >= size); 00050 00051 /*do { 00052 seq = (seq >> 1) ^ ((seq & 1) * mask); 00053 } while(seq >= size);*/ 00054 } while(seq != 1); // Loop 00055 00056 cerr << width << ", " << height << endl; 00057 cerr << count << " vs " << width * height << endl; 00058 ASSERT(count == width * height); 00059 #endif 00060 } 00061 00062 #if 0 00063 /* A Digital Dissolve Effect 00064 by Mike Morton 00065 from "Graphics Gems", Academic Press, 1990 00066 00067 user must provide copy() function. 00068 */ 00069 00070 /* 00071 * Code fragment to advance from one element to the next. 00072 * 00073 * int reg; // current sequence element 00074 * reg = 1; // start in any non-zero state 00075 * if (reg & 1) // is the bottom bit set? 00076 * reg = (reg >>1) ^ MASK; // yes: toss out 1 bit; XOR in mask 00077 * else reg = reg >>1; // no: toss out 0 bit 00078 */ 00079 00080 int randmasks[32]; /* Gotta fill this in yourself. */ 00081 00082 void dissolve1 (int height, int width) { 00083 int pixels, lastnum; /* number of pixels; */ 00084 /* last pixel's number */ 00085 int regwidth; /* "width" of sequence generator */ 00086 register long mask; /* mask to XOR with to*/ 00087 /* create sequence */ 00088 register unsigned long element; 00089 /* one element of random sequence */ 00090 register int row, column; 00091 /* row and column numbers for a pixel */ 00092 00093 /* Find smallest register which produces enough pixel numbers */ 00094 pixels = height * width; /* compute number of pixels */ 00095 /* to dissolve */ 00096 lastnum = pixels-1; /* find last element (they go 0..lastnum) */ 00097 regwidth = bitwidth ((unsigned int)lastnum); /* how wide must the */ 00098 /* register be? */ 00099 mask = randmasks [regwidth]; /* which mask is for that width? */ 00100 00101 /* Now cycle through all sequence elements. */ 00102 00103 element = 1; /* 1st element (could be any nonzero) */ 00104 00105 do { 00106 row = element / width; /* how many rows down is this pixel? */ 00107 column = element % width; /* and how many columns across? */ 00108 if (row < height) /* is this seq element in the array? */ 00109 copy (row, column); /* yes: copy the (r,c)'th pixel */ 00110 00111 /* Compute the next sequence element */ 00112 if (element & 1) /* is the low bit set? */ 00113 element = (element >>1)^mask; /* yes: shift value, */ 00114 /* XOR in mask */ 00115 else element = (element >> 1); /* no: just shift the value */ 00116 } while (element != 1); /* loop until we return */ 00117 00118 /* to original element */ 00119 copy (0, 0); /* kludge: the loop doesn't produce (0,0) */ 00120 } 00121 00122 #endif 00123 00124 00125 // force explicit template specialization of DissolveSampleGenerator and 00126 // DissolveSampleGeneratorThread 00127 #include <generators.h> 00128 DECLARE_SAMPLE_GENERATOR(Dissolve); 00129
Generated on 28 Feb 2009 for Milton by
1.5.6