HilbertSampleGenerator.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   HilbertSampleGenerator.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   December 2006
00005    
00006    @brief
00007       Recursive space-filling L-System represented graphically
00008    
00009    @see http://en.wikipedia.org/wiki/Hilbert_curve
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #include "HilbertSampleGenerator.h"
00013 #include <QtCore>
00014 
00015 template <class SG>
00016 void HilbertSG<SG>::generate(PointSampleList &outSamples, 
00017                              const Viewport &viewport)
00018 {
00019 #if 0
00020    const unsigned width   = viewport.getWidth();
00021    const unsigned height  = viewport.getHeight();
00022    
00023    const real_t binWidth  = viewport.getInvWidth();
00024    const real_t binHeight = viewport.getInvHeight();
00025    
00026    for(unsigned depth = 2; depth < 8; ++depth) {
00027       const std::string &system = process(depth);
00028       
00029       cerr << depth << endl;
00030       cerr << system << endl;
00031       unsigned x = 0, y = height - 1;
00032       unsigned lenX = width, lenY = height;
00033       real_t angle = M_PI / 2.0; // 90 degree turns
00034       real_t theta = 0;
00035       
00036       for(unsigned i = depth; i--;) {
00037          lenX >>= 1;
00038          lenY >>= 1;
00039       }
00040       
00041       for(unsigned i = 0; i < system.length(); ++i) {
00042          const char cur = system[i];
00043          
00044          switch(cur) {
00045             case 'F':
00046                {
00047                   unsigned newX = (unsigned)round(x + lenX * cos(theta));
00048                   unsigned newY = (unsigned)round(y + lenY * sin(theta));
00049                   
00050                   if (newX == x) {
00051                      for(unsigned j = MIN(newY, y); j < MAX(newY, y); ++j) {
00052                         SG::_addSample(PointSample(min0 + x, min1 + j), 
00053                                        outSamples);
00054                      }
00055                   } else if (newY == y) {
00056                      for(unsigned j = MIN(newX, x); j < MAX(newX, x); ++j) {
00057                         SG::_addSample(PointSample(min0 + j, min1 + y), 
00058                                        outSamples);
00059                      }
00060                   } else {
00061                      cerr << x << ", " << y << " vs " << newX << ", " << newY << endl;
00062                      ASSERT(0);
00063                   }
00064                   
00065                   x = newX;
00066                   y = newY;
00067                   
00068                   cerr << "(" << x << ", " << y << ")" << endl;
00069                }
00070                break;
00071             case '-':
00072                theta += angle;
00073                break;
00074             case '+':
00075                theta -= angle;
00076                break;
00077             default:
00078                break;
00079          }
00080       }
00081    }
00082 #endif
00083 }
00084 
00085 template <class SG>
00086 std::string HilbertSG<SG>::_processRule(char c) {
00087    if (c == 'L')
00088       return "+RF-LFL-FR+";
00089    if (c == 'R')
00090       return "-LF+FRF+FL-";
00091    
00092    return "";
00093 }
00094 
00095 // force explicit template specialization of DissolveSampleGenerator and 
00096 // DissolveSampleGeneratorThread
00097 #include <generators.h>
00098 DECLARE_SAMPLE_GENERATOR(Hilbert);
00099 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6