217 lines
6.6 KiB
Java
217 lines
6.6 KiB
Java
/*
|
|
* Author: Cedric Holzl - Mohamed Khadri
|
|
* Sciper: 257844 - 261203
|
|
*/
|
|
package ch.epfl.alpano.gui;
|
|
|
|
import java.beans.Beans;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import javafx.beans.property.ObjectProperty;
|
|
import javafx.beans.property.ReadOnlyObjectProperty;
|
|
import javafx.beans.property.SimpleObjectProperty;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.image.Image;
|
|
import ch.epfl.alpano.Panorama;
|
|
import ch.epfl.alpano.PanoramaComputer;
|
|
import ch.epfl.alpano.dem.ContinuousElevationModel;
|
|
import ch.epfl.alpano.mapzen.MapzenManager;
|
|
import ch.epfl.alpano.summit.Summit;
|
|
import static ch.epfl.alpano.gui.PanoramaRenderer.renderPanorama;
|
|
import static javafx.application.Platform.runLater;
|
|
|
|
|
|
/**
|
|
* Class used to link the panorama computing with the Graphical interface (through the PanoramaParametersBean)
|
|
*/
|
|
public class PanoramaComputerBean extends Beans {
|
|
|
|
private final ObjectProperty<Panorama> panoramaProperty;
|
|
private final ObjectProperty<PanoramaUserParameters> parametersProperty;
|
|
private final ObjectProperty<Image> imageProperty;
|
|
private final ObjectProperty<ObservableList<Node>> labelsProperty;
|
|
private final ObjectProperty<ContinuousElevationModel> cDEM;
|
|
private final ObjectProperty<CustomPainters> imp;
|
|
private final ObjectProperty<Boolean> downloadProperty;
|
|
private final ObjectProperty<String> downloadTextProperty;
|
|
private final List<Summit> summits;
|
|
private final MapzenManager HGTGetter = new MapzenManager();
|
|
|
|
/**
|
|
* Constructs a bean for a panoramaComputer
|
|
* @param summits : a list of summits
|
|
*/
|
|
public PanoramaComputerBean(List<Summit> summits){
|
|
this.cDEM = new SimpleObjectProperty<ContinuousElevationModel>();
|
|
this.cDEM.bind(HGTGetter.cDEM());
|
|
this.downloadProperty = new SimpleObjectProperty<Boolean>(false);
|
|
this.summits = summits;
|
|
this.parametersProperty = new SimpleObjectProperty<PanoramaUserParameters>(null);
|
|
ObservableList<Node> oList = FXCollections.observableList(new ArrayList<Node>());
|
|
this.labelsProperty = new SimpleObjectProperty<ObservableList<Node>>(oList);
|
|
this.panoramaProperty = new SimpleObjectProperty<Panorama>(null);
|
|
this.imageProperty = new SimpleObjectProperty<Image>(null);
|
|
this.imp = new SimpleObjectProperty<CustomPainters>(CustomPainters.GRADDEMPOST);
|
|
HGTGetter.cDEM().addListener(
|
|
(b, o, n) -> runLater(this::updatePanorama));
|
|
this.downloadTextProperty = new SimpleObjectProperty<String>();
|
|
HGTGetter.text().addListener(
|
|
(b, o, n) -> runLater(this::updateDownloadText));
|
|
this.imp.addListener( (b, o, n) -> runLater(this::repaintPanorama));
|
|
parametersProperty.addListener((b, o, n) -> this.downloadHGT());
|
|
}
|
|
|
|
/**
|
|
* Returns the elevation model property object
|
|
* @return ContinuousElevationModel property object
|
|
*/
|
|
ReadOnlyObjectProperty<ContinuousElevationModel> cDem(){
|
|
return this.cDEM;
|
|
}
|
|
|
|
/**
|
|
* Returns the panorama property object
|
|
* @return panorama property object
|
|
*/
|
|
ReadOnlyObjectProperty<Panorama> panoramaProperty(){
|
|
return panoramaProperty;
|
|
}
|
|
|
|
/**
|
|
* Returns the parameters property object
|
|
* @return parameters property object
|
|
*/
|
|
ObjectProperty<PanoramaUserParameters> parametersProperty(){
|
|
return parametersProperty;
|
|
}
|
|
|
|
/**
|
|
* Returns the image property object
|
|
* @return image property object
|
|
*/
|
|
ReadOnlyObjectProperty<Image> imageProperty(){
|
|
return imageProperty;
|
|
}
|
|
|
|
/**
|
|
* Returns the labels property object
|
|
* @return labels property object
|
|
*/
|
|
ReadOnlyObjectProperty<ObservableList<Node>> labelsProperty(){
|
|
return labelsProperty;
|
|
}
|
|
|
|
/**
|
|
* Returns the painter property object
|
|
* @return Custom Painter property object
|
|
*/
|
|
ReadOnlyObjectProperty<CustomPainters> painterProperty() {
|
|
return imp;
|
|
}
|
|
|
|
/**
|
|
* Returns the download property object
|
|
* This object is used to set if Mapzen is currently downloading
|
|
* @return boolean download property object
|
|
*/
|
|
ReadOnlyObjectProperty<Boolean> downloadProperty(){
|
|
return downloadProperty;
|
|
}
|
|
|
|
/**
|
|
* Returns the labels
|
|
* @return labels
|
|
*/
|
|
ObservableList<Node> getLabels(){
|
|
return labelsProperty.get();
|
|
}
|
|
|
|
/**
|
|
* Returns the panorama
|
|
* @return panorama
|
|
*/
|
|
Panorama getPanorama(){
|
|
return panoramaProperty.get();
|
|
}
|
|
|
|
/**
|
|
* Returns the parameters
|
|
* @return parameters
|
|
*/
|
|
PanoramaUserParameters getParameters(){
|
|
return parametersProperty.get();
|
|
}
|
|
|
|
/**
|
|
* Updates the parameters
|
|
* @param newParameters : new PanoramaUserParameters
|
|
*/
|
|
void setParameters(PanoramaUserParameters newParameters){
|
|
this.parametersProperty.set(newParameters);
|
|
}
|
|
|
|
/**
|
|
* Updates the custom painter
|
|
* @param cp : new painter
|
|
*/
|
|
void setPainter(CustomPainters cp) {
|
|
imp.set(cp);
|
|
}
|
|
|
|
/**
|
|
* Retuns the image
|
|
* @return image
|
|
*/
|
|
Image getImage(){
|
|
return imageProperty.get();
|
|
}
|
|
|
|
/**
|
|
* Text displayed when downloading property object
|
|
* @return download text property object
|
|
*/
|
|
ReadOnlyObjectProperty<String> downloadTextProperty(){
|
|
return downloadTextProperty;
|
|
}
|
|
|
|
/**
|
|
* Updates the download text getting new text from the MapzenManager
|
|
*/
|
|
private void updateDownloadText(){
|
|
this.downloadTextProperty.set(HGTGetter.text().get());
|
|
}
|
|
|
|
/**
|
|
* Downloads the HGT Files
|
|
*/
|
|
private void downloadHGT(){
|
|
this.downloadProperty.set(true);
|
|
HGTGetter.update(this.getParameters().panoramaDisplayParameters());
|
|
}
|
|
|
|
/**
|
|
* Repaints the panorama
|
|
*/
|
|
private void repaintPanorama(){
|
|
if(this.getPanorama()!=null)
|
|
this.imageProperty.set(renderPanorama(this.getPanorama(), imp.get().painter(this.getPanorama())));
|
|
}
|
|
|
|
/**
|
|
* Computes the new panorama
|
|
*/
|
|
private void updatePanorama() {
|
|
this.downloadProperty.set(false);
|
|
Panorama panorama = new PanoramaComputer(cDEM.get()).computePanorama(this.getParameters().panoramaComputeParameters());
|
|
List<Node> newLabels = new Labelizer(cDEM.get(), summits).labels(this.getParameters().panoramaDisplayParameters());
|
|
this.panoramaProperty.set(panorama);
|
|
this.imageProperty.set(renderPanorama(panorama, imp.get().painter(panorama)));
|
|
this.labelsProperty().get().setAll(newLabels);
|
|
}
|
|
|
|
|
|
|
|
}
|