source: subversion/applications/rendering/genericHeatmapRender/locationFinder_regularGrid.py @ 30554

Last change on this file since 30554 was 16229, checked in by stevefaeembra, 10 years ago

added grid and T@H heatmap code and demos

  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1# -*- coding: UTF8 -*-
2'''
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License along
14    with this program; if not, write to the Free Software Foundation, Inc.,
15    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16'''
17
18from location import location
19import string
20from locationFinder import locationFinder
21import random
22
23
24class locationFinder_regularGrid(locationFinder):
25    '''
26    Responsible for generating a list of location objects
27    this implementation generates a grid of regularly spaced
28    points (and generates random values for each)
29    '''
30           
31    def __init__(self):
32        '''
33        Constructor
34        '''
35       
36    def query(self,query=None,peturb=0.05,sampleevery=100,steps=200):
37        '''
38        generate a regular grid of points
39        query is not used at present
40        steps is resolution on both axes
41        sampleevery is the random sample rate (e.g. 100=choose 1 in every 100 points)
42        set sampleevery to None to include all points
43       
44        peturb can be used to add a small random nudge to each point
45        this can improve the aesthetics when zoomed in by
46        softening the 'diamond' effect.
47        '''
48        print "generating mesh"
49        if sampleevery==None:
50            threshold=2.0
51        else:
52            threshold=1.0-(1.0/sampleevery)
53        bbox=self.bounds
54        xstep=float((bbox[2]-bbox[0])/float(steps))
55        ystep=float((bbox[3]-bbox[1])/float(steps))
56        maxy=int(steps)
57        maxx=int(steps)
58        for y in range(0,maxy):
59            yy=bbox[1]+(y*ystep)
60            for x in range(0,maxx):
61                if random.random()>=threshold:
62                    xx=bbox[0]+(x*xstep)+(random.random()*peturb)
63                    r=random.random()
64                    self.addPoint('', r, xx,yy+(random.random()*peturb) )
65                    #print "(%s,%s)" % (xx,yy)
66           
Note: See TracBrowser for help on using the repository browser.