Revision 2129

View differences:

org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/src/main/java/org/gvsig/raster/principalcomponents/algorithm/PCAStatisticsProcess.java
242 242
	}
243 243
	
244 244
	private void loadDataStoreStatistics() {
245
		if(store.getStatistics().isCalculated()) {
245
		if(isAnalizedEntireLayer(inputWindow, rois, store) && store.getStatistics().isCalculated()) {
246 246
			double[] max = store.getStatistics().getMax();
247 247
			double[] min = store.getStatistics().getMin();
248 248
			double[] mean = store.getStatistics().getMean();
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/src/main/java/org/gvsig/raster/principalcomponents/algorithm/PrincipalComponentsProcess.java
1 1
package org.gvsig.raster.principalcomponents.algorithm;
2 2

  
3
import java.awt.geom.Point2D;
4 3
import java.awt.geom.Rectangle2D;
5 4
import java.util.List;
6 5

  
......
35 34
	public static final String    EXTENT             = "EXTENT";
36 35
	public static final String    GRAPHIC_DATA       = "GRAPHIC_DATA";
37 36
	public static final String    BANDS              = "BANDS";
37
	public static final String    WINDOW             = "WINDOW";
38 38
	
39 39
	private RasterDataStore       store              = null;
40 40
	private String                filename           = null;
......
42 42
	private PCStatsDataStructure  pcStatistics       = null;
43 43
	private List<ROI>             rois               = null;
44 44
	private String                roiEPSG            = null;
45
	private	Extent 				  inputWindow		 = null;
45 46
	private Extent                extentResult       = null;
46 47
	private boolean[]             selectedPCs        = null;
47 48
	private boolean[]             bands              = null;
......
56 57
		registerInputParameter(ROI_EPSG, String.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
57 58
		registerInputParameter(SELECTEDPCS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
58 59
		registerInputParameter(BANDS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
60
		registerInputParameter(WINDOW, Extent.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
59 61
		
60 62
		registerOutputParameter(FILENAME, String.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
61 63
		registerOutputParameter(GRAPHIC_DATA, Double[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
......
68 70
		bands = (boolean[]) getParam(BANDS);
69 71
		pcStatistics = (PCStatsDataStructure) getParam(PCSTATISTICS);
70 72
		roiEPSG = getStringParam(ROI_EPSG);
73
		inputWindow = getParam(WINDOW) != null ? (Extent)getParam(WINDOW) : null;
71 74
	}
72
	
73
	
74
	/**
75
	 * Gets the bounding box of the source in pixel coordinates
76
	 * @param ext
77
	 * @return
78
	 */
79
	private Rectangle2D getSourcePxBox(Extent ext) {
80
		if(rois == null)
81
			return new Rectangle2D.Double(0, 0, store.getWidth(), store.getHeight());
82
		Point2D p1 = store.worldToRaster(new Point2D.Double(ext.getULX(), ext.getULY()));
83
		Point2D p2 = store.worldToRaster(new Point2D.Double(ext.getLRX(), ext.getLRY()));
84
		return new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p2.getX() - p1.getX()), Math.abs(p2.getY() - p1.getY()));
85
	}
86 75

  
87 76
	public void process() throws ProcessInterruptedException, ProcessException {
88 77
		insertLineLog(Messages.getText("processing_pc"));
......
104 93
				new PrincipalComponentsException("Error cloning the input DataStore", e);
105 94
			}
106 95
			
107
			extentResult = getExtentResult(null, rois, store);
108
			Rectangle2D sourcePxBBox = getSourcePxBox(extentResult);
96
			extentResult = getExtentResult(inputWindow, rois, store);
97
			Rectangle2D sourcePxBBox = getSourcePxBox(extentResult, store);
109 98
			
110 99
			double cellSize = store.getCellSize();
111 100
			
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.sextante/src/main/java/org/gvsig/raster/principalcomponents/PrincipalComponentsSextanteAlgorithm.java
33 33
    public static final String USE_ROI           = "USE_ROI";
34 34
    
35 35
    private boolean            useROI            = false;
36
    private DataProcess        taskStats         = null;
37
    private DataProcess        taskPC            = null;
38
    
36 39

  
37 40
    public void defineCharacteristics() {
38 41
        setName(getTranslation("principalcomponents"));
......
58 61
    	
59 62
    	FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject());
60 63
    	IRasterLayer output = null;
61
    	DataProcess task = null;
62
    	AnalysisExtent ext = getAnalysisExtent();
63
    	Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
64
    			ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
65
		try {
66
			output = getNewRORasterLayer(
67
					RESULT, 
68
					Sextante.getText("principalcomponents_description"), 
69
					input.getDataType(), 
70
					input.getBandsCount());
71
			task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("PrincipalComponentsProcess");
72
		} catch (ProcessException e1) {
73
			 Sextante.addErrorToLog(e1);
74
		} 
75
    	
64

  
65
    	output = getNewRORasterLayer(
66
    			RESULT, 
67
    			Sextante.getText("principalcomponents_description"), 
68
    			input.getDataType(), 
69
    			input.getBandsCount());
70

  
76 71
    	String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT);
77
		
78
		try {
79
			setProgressText(Sextante.getText("stadistics"));
80
			task = createStatisticsProcess(lyrRaster.getDataStore());
81
			task.execute();
82
			HashMap<String, Object> params = task.getResult();
72

  
73
    	try {
74
    		setProgressText(getTranslation("stadistics"));
75
			taskStats = createStatisticsProcess(lyrRaster.getDataStore());
76
			taskStats.execute();
77
			HashMap<String, Object> params = taskStats.getResult();
83 78
			PCStatsDataStructure stats = (PCStatsDataStructure)params.get("STATS_RESULT");
84 79
			
85
			setProgressText(Sextante.getText("calc_components"));
86
			task = createPCAProcess(lyrRaster.getDataStore(), fileName, stats);
87
			task.execute();
88
			params = task.getResult();
80
			setProgressText(getTranslation("calc_components"));
81
			taskPC = createPCAProcess(lyrRaster.getDataStore(), fileName, stats);
82
			taskPC.execute();
83
			params = taskPC.getResult();
89 84
			
90 85
			((FLyrRasterIRasterLayer)output).setBaseDataObject(fileName);
91 86
		} catch (ProcessInterruptedException e) {
......
100 95
        return true;
101 96
    }
102 97
    
103

  
98
    /**
99
     * Creates a process to calculate statistics
100
     * @param inputStore
101
     * @return
102
     * @throws ProcessException
103
     */
104 104
    private DataProcess createStatisticsProcess(RasterDataStore inputStore) throws ProcessException {
105
    	DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
106
    	task.setActions(this);
107
    	List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
105
    	DataProcess taskStats = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
106
    	taskStats.setActions(this);
107
    	List<String> params = taskStats.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
108 108
    	for (int i = 0; i < params.size(); i++) {
109 109
    		String paramName = params.get(i);
110
    		Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName);
110
    		Class<?> paramType = taskStats.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName);
111 111
    		if(paramType == RasterDataStore.class) {
112
    			task.addParam(paramName, (RasterDataStore)inputStore);
112
    			taskStats.addParam(paramName, (RasterDataStore)inputStore);
113 113
    		}
114 114
    		if(paramName.equals("BANDS")) {
115 115
    			boolean[] bands = new boolean[inputStore.getBandCount()];
116 116
    			for (int j = 0; j < bands.length; j++) {
117 117
					bands[j] = true;
118 118
				}
119
    			task.addParam(paramName, bands);
119
    			taskStats.addParam(paramName, bands);
120 120
    		}
121 121

  
122 122
    		if(paramName.equals("ROI_EPSG") && useROI) {
123
    			task.addParam(paramName, "EPSG:4326");
123
    			taskStats.addParam(paramName, "EPSG:4326");
124 124
    		}
125
    		
126
    		if(paramName.equals("WINDOW")) {
127
    			AnalysisExtent ext = getAnalysisExtent();
128
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
129
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
130
    			Extent inputBbox = inputStore.getExtent();
131
    			if(bbox.getULX() != inputBbox.getULX() || 
132
    				bbox.getULY() != inputBbox.getULY() || 
133
    				bbox.getLRX() != inputBbox.getLRX() || 
134
    				bbox.getLRY() != inputBbox.getLRY()) {
135
    				taskStats.addParam(paramName, bbox);
136
    			}
137
    		}
125 138
    	}
126
    	return task;
139
    	return taskStats;
127 140
    }
128 141
    
129 142
    private DataProcess createPCAProcess(RasterDataStore inputStore, String fileName, PCStatsDataStructure stats) throws ProcessException {
130
    	DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
131
    	task.setActions(this);
132
    	List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
143
    	DataProcess taskPC = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
144
    	taskPC.setActions(this);
145
    	List<String> params = taskPC.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
133 146
    	for (int i = 0; i < params.size(); i++) {
134 147
    		String paramName = params.get(i);
135
    		Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL, paramName);
148
    		Class<?> paramType = taskPC.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL, paramName);
136 149
    		if(paramType == RasterDataStore.class) {
137
    			task.addParam(paramName, (RasterDataStore)inputStore);
150
    			taskPC.addParam(paramName, (RasterDataStore)inputStore);
138 151
    		}
139 152
			
140 153
			if(paramType == Boolean[].class) {
......
142 155
    			for (int j = 0; j < bands.length; j++) {
143 156
					bands[j] = true;
144 157
				}
145
				task.addParam(paramName, bands);
158
    			taskPC.addParam(paramName, bands);
146 159
			}
147 160
			
148 161
			if(paramType == PCStatsDataStructure.class) {
149
				task.addParam(paramName, stats);
162
				taskPC.addParam(paramName, stats);
150 163
			}
151 164
			
152 165
			if(paramName.equals("PATH")) {
153
				task.addParam(paramName, fileName);
166
				taskPC.addParam(paramName, fileName);
154 167
			}
155 168
			
156 169
			if(paramName.equals("ROI_EPSG") && useROI) {
157
    			task.addParam(paramName, "EPSG:4326");
170
				taskPC.addParam(paramName, "EPSG:4326");
158 171
    		}
172
			
173
			if(paramName.equals("WINDOW")) {
174
    			AnalysisExtent ext = getAnalysisExtent();
175
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
176
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
177
    			Extent inputBbox = inputStore.getExtent();
178
    			if(bbox.getULX() != inputBbox.getULX() || 
179
    				bbox.getULY() != inputBbox.getULY() || 
180
    				bbox.getLRX() != inputBbox.getLRX() || 
181
    				bbox.getLRY() != inputBbox.getLRY()) {
182
    				taskPC.addParam(paramName, bbox);
183
    			}
184
    		}
159 185
    	}
160
    	return task;
186
    	return taskPC;
161 187
    }
162 188

  
163 189
	public void interrupted() {
......
169 195
	}
170 196

  
171 197
	public void updateProgress(int current, int total) {
172
		int sextanteProgress = (current * 100) / total;
173
		getStatus().setCurValue(sextanteProgress);
174
		setProgress(sextanteProgress, 100);
198
		boolean cancelled = setProgress(current, total);
199
		
200
		if(!cancelled) {
201
			if(taskStats != null)
202
				taskStats.actionCanceled(null);
203
			if(taskPC != null)
204
				taskPC.actionCanceled(null);
205
		}
175 206
	}
176 207
    
177 208
    /*
org.gvsig.raster.reproject/trunk/org.gvsig.raster.reproject/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/PrepareLayerAskProjection.java
315 315

  
316 316
	public void interrupted() {
317 317
	}
318
	
319
	public void updateProgress(int current, int total) {
320
		
321
	}
318 322
}
org.gvsig.raster.reproject/trunk/org.gvsig.raster.reproject/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectListener.java
226 226
	}
227 227

  
228 228
	public void interrupted() {
229
		
229 230
	}
231
	
232
	public void updateProgress(int current, int total) {
233
		
234
	}
230 235
}
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ClippingProcess.java
509 509
			return;
510 510

  
511 511
		if(viewName != null) {
512
			if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", this)) {
512
			if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", null)) {
513 513

  
514 514
				try {
515 515
					FLayer lyr = RasterMainPluginUtils.loadLayer(viewName, fileName, null);
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/ProcessUtils.java
313 313
	 * Gets the bounding box taking into account whether there are ROIs or not
314 314
	 * @return
315 315
	 */
316
	public Extent getExtentResult(Extent extent, List<ROI> rois, RasterDataStore store) {
317
		if(extent != null)
318
			return extent.intersection(store.getExtent());
316
	public Extent getExtentResult(Extent window, List<ROI> rois, RasterDataStore store) {
317
		if(window != null)
318
			return window.intersection(store.getExtent());
319 319
		if(rois == null)
320 320
			return store.getExtent();
321 321
		else {
......
331 331
	}
332 332
	
333 333
	/**
334
	 * Returns true if the algorithm is applied to the entire layer
335
	 * @param extent
336
	 * @param rois
337
	 * @param store
338
	 * @return
339
	 */
340
	public boolean isAnalizedEntireLayer(Extent window, List<ROI> rois, RasterDataStore store) {
341
		if(window == null) {
342
			if(rois == null || rois.size() == 0)
343
				return true;
344
		}
345
		return false;
346
	}
347
	
348
	/**
334 349
	 * Gets the bounding box of the source in pixel coordinates
335 350
	 * @param resultExtent
336 351
	 * @return
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/DataProcess.java
152 152
	 * @throws ProcessException 
153 153
	 */
154 154
	public void execute() throws ProcessInterruptedException, ProcessException {
155
		taskEventManager = RasterLocator.getManager().createRasterTask(this);
155 156
		init();
156 157
		process();
157 158
		
......
173 174
		long t1 = new java.util.Date().getTime();
174 175

  
175 176
		try {
176
			taskEventManager = RasterLocator.getManager().createRasterTask(this);
177 177
			execute();
178 178
		} catch (ProcessInterruptedException e) {
179 179
			if (externalActions != null)
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/RasterSwingLibrary.java
61 61
		String string1 = Messages.getText("yes");
62 62
		String string2 = Messages.getText("no");
63 63
		Object[] options = {string1, string2};
64
		int n = JOptionPane.showOptionDialog((Component)parentWindow,
64
		Component parent = null;
65
		if(parentWindow instanceof Component)
66
			parent = (Component)parentWindow;
67
		int n = JOptionPane.showOptionDialog(parent,
65 68
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
66 69
					Messages.getText("confirmacion"),
67 70
					JOptionPane.YES_NO_OPTION,
......
78 81
	public static void messageBoxError(String msg, Object parentWindow) {
79 82
		String string = Messages.getText("accept");
80 83
		Object[] options = {string};
81
		JOptionPane.showOptionDialog((Component)parentWindow,
84
		Component parent = null;
85
		if(parentWindow instanceof Component)
86
			parent = (Component)parentWindow;
87
		JOptionPane.showOptionDialog(parent,
82 88
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
83 89
					Messages.getText("confirmacion"),
84 90
					JOptionPane.OK_OPTION,
......
91 97
	public static void messageBoxInfo(String msg, Object parentWindow) {
92 98
		String string = Messages.getText("accept");
93 99
		Object[] options = {string};
94
		JOptionPane.showOptionDialog((Component)parentWindow,
100
		Component parent = null;
101
		if(parentWindow instanceof Component)
102
			parent = (Component)parentWindow;
103
		JOptionPane.showOptionDialog(parent,
95 104
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
96 105
					Messages.getText("confirmacion"),
97 106
					JOptionPane.OK_OPTION,

Also available in: Unified diff