Revision 2400

View differences:

org.gvsig.legend.heatmap/trunk/org.gvsig.legend.heatmap/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.java
18 18
import org.gvsig.fmap.dal.feature.FeatureStore;
19 19
import org.gvsig.fmap.dal.feature.FeatureType;
20 20
import org.gvsig.fmap.geom.Geometry;
21
import org.gvsig.fmap.geom.GeometryUtils;
21 22
import org.gvsig.fmap.geom.primitive.Point;
22 23
import org.gvsig.fmap.mapcontext.MapContextException;
23 24
import org.gvsig.fmap.mapcontext.ViewPort;
......
114 115
            }
115 116
        }
116 117

  
117
        public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
118
        public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi) {
118 119
            try {
119 120
                ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
120 121
                Color c;
......
124 125
                        if( cancel.isCanceled() ) {
125 126
                            return;
126 127
                        }
128
                        if (roi!=null) {
129
                            Point point = GeometryUtils.createPoint(x, y);
130
                            if (!roi.intersects(point)) {
131
                                continue;
132
                            }
133
                        }
127 134
                        double value = this.grid[x][y];
128 135
                        if( value > 0 ) {
129 136
                            int icolor = (int) (value * maxIndexColor / maxValue);
......
140 147
            }
141 148
        }
142 149

  
143
        public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
150
        public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi) {
144 151
            try {
145 152
                Color c;
146 153
                int maxIndexColor = colorTable.length-1;
......
149 156
                        if( cancel.isCanceled() ) {
150 157
                            return;
151 158
                        }
159
                        if (roi!=null) {
160
                            Point point = GeometryUtils.createPoint(x, y);
161
                            if (!roi.intersects(point)) {
162
                                continue;
163
                            }
164
                        }
152 165
                        double value = this.grid[x][y];
153 166
                        if( value > 0 ) {
154 167
                            int icolor = (int) (value * maxIndexColor / maxValue);
......
176 189
    private Color rampColdColor;
177 190
    private Color rampHotColor;
178 191
    private int rampNumColors;
179

  
192
    private Geometry roi;
193
    
180 194
    public DefaultHeatmapLegend() {
195
        
181 196
        this.defaultSymbol = new SimpleTextSymbol();
182 197
        this.algorithm = new DensityAlgorithm(30);
183 198
        this.colorTableHotColorAlpha = 255;
......
245 260
        int saved_distance = this.algorithm.getDistance();
246 261
        try {
247 262
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
263
            Geometry theROI = null;
264
            if (this.roi!=null) {
265
                theROI = this.roi.cloneGeometry();
266
                theROI.transform(viewPort.getAffineTransform());
267
            }
248 268
            this.algorithm.setDistance(distance);
249 269
            this.algorithm.init(image.getWidth(), image.getHeight());
250 270
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
251 271
            if( !cancel.isCanceled() ) {
252
                this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
272
                this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI);
253 273
            }
254 274
        } finally {
255 275
            this.algorithm.setDistance(saved_distance);
......
267 287
            double dpi = viewPort.getDPI();
268 288
            // Ver CartographicSupportToolkit.getCartographicLength
269 289
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
270
            
290
            Geometry theROI = null;
291
            if (this.roi!=null) {
292
                theROI = this.roi.cloneGeometry();
293
                theROI.transform(viewPort.getAffineTransform());
294
            }
271 295
            this.algorithm.setDistance(distance);
272 296
            this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight());
273 297
            BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
274 298
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
275 299
            if (!cancel.isCanceled()) {
276
                this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
300
                this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI);
277 301
                g.drawImage(image, 0, 0, null);
278 302
            }
279 303
        } finally {
......
446 470

  
447 471
        return x;
448 472
    }
473
    @Override
474
    public void setROI(Geometry roi) {
475
        this.roi = roi;
476
    }
449 477

  
450 478
    @Override
479
    public Geometry getROI() {
480
        return this.roi;
481
    }
482
    
483
    @Override
451 484
    public Image getImageLegend() {
452 485
        if( this.imageLegend==null ) {
453 486
            BufferedImage img = new BufferedImage(80, 20, BufferedImage.TYPE_INT_RGB);
org.gvsig.legend.heatmap/trunk/org.gvsig.legend.heatmap/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegend.java
1 1
package org.gvsig.legend.heatmap.lib.api;
2 2

  
3 3
import java.awt.Color;
4
import org.gvsig.fmap.geom.Geometry;
4 5
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
5 6

  
6 7
public interface HeatmapLegend extends IVectorLegend {
......
16 17
    public Color[] getSourceColorTable();
17 18

  
18 19
    public Color[] getTargetColorTable();
20
    
21
    public Geometry getROI();
22
    
23
    public void setROI(Geometry roi);
19 24

  
20 25
    public boolean useRamp();
21 26

  

Also available in: Unified diff