Skip to content
Snippets Groups Projects
Verified Commit bb0b3f89 authored by philippe.verley_ird.fr's avatar philippe.verley_ird.fr Committed by philippe.verley_ird.fr
Browse files

Added progressBar to the VoxToObj dialog pane.

parent 50665e88
No related branches found
No related tags found
No related merge requests found
......@@ -32,8 +32,8 @@ import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javax.vecmath.Point3d;
......@@ -47,8 +47,8 @@ import javax.vecmath.Point3i;
*/
public class ObjExporterDialogController implements Initializable {
private FileChooserContext fcVoxelFile = new FileChooserContext();
private FileChooserContext fcOutputFile = new FileChooserContext();
private final FileChooserContext fcVoxelFile = new FileChooserContext();
private final FileChooserContext fcOutputFile = new FileChooserContext();
private Stage stage;
......@@ -70,26 +70,28 @@ public class ObjExporterDialogController implements Initializable {
@FXML
private VBox vboxMaterialParameters;
@FXML
private HBox hboxSizeFunctionOfPADParameters;
@FXML
private TextField textfieldPADMax;
@FXML
private TextField textfieldAlpha;
@FXML
private ProgressBar progressBar;
//
private final String TITLE = "AMAPVox: VoxToObj export tool";
/**
* Initializes the controller class.
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
fcVoxelFile = new FileChooserContext();
comboboxGradient.getItems().addAll(Util.AVAILABLE_GRADIENT_COLOR_NAMES);
comboboxGradient.getSelectionModel().selectFirst();
comboboxAttribute.getSelectionModel().selectFirst();
vboxMaterialParameters.disableProperty().bind(checkboxMaterial.selectedProperty().not());
progressBar.setPrefWidth(Double.MAX_VALUE);
}
@FXML
......@@ -122,6 +124,10 @@ public class ObjExporterDialogController implements Initializable {
try {
reader = new VoxelFileRawReader(new File(textfieldInputVoxelFile.getText()), true);
VoxelSpaceInfos infos = reader.getVoxelSpaceInfos();
Point3i split = infos.getSplit();
double nprogress = split.x * split.y * split.z;
int ipgrogress = 1;
int padAttributeIndex = comboboxAttribute.getItems().indexOf("PadBVTotal") - 3;
int selectedAttributeIndex = comboboxAttribute.getSelectionModel().getSelectedIndex() - 3;
......@@ -136,6 +142,8 @@ public class ObjExporterDialogController implements Initializable {
Statistic attributeStat = new Statistic();
while (iterator.hasNext()) {
// print progress
progressBar.setProgress(ipgrogress++/nprogress);
RawVoxel voxel = iterator.next();
......@@ -165,7 +173,10 @@ public class ObjExporterDialogController implements Initializable {
Iterator<RawVoxel> iterator = reader.iterator();
ipgrogress = 1;
while (iterator.hasNext()) {
// print progress
progressBar.setProgress(ipgrogress++/nprogress);
RawVoxel voxel = iterator.next();
......@@ -218,11 +229,14 @@ public class ObjExporterDialogController implements Initializable {
} catch (Exception ex) {
DialogHelper.showErrorDialog(stage, ex);
progressBar.setProgress(0.d);
return;
}
File materialFile = new File(replaceExtension(outputFile.getAbsolutePath(), "mtl"));
double nprogress = cubeVertices.size() + faces.size();
double iprogress = 1;
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
if (checkboxMaterial.isSelected()) {
......@@ -230,6 +244,9 @@ public class ObjExporterDialogController implements Initializable {
}
for (Point3d point : cubeVertices) {
// print progress
progressBar.setProgress(iprogress++/nprogress);
// write vertex
writer.write("v " + point.x + " " + point.y + " " + point.z + "\n");
}
......@@ -237,6 +254,8 @@ public class ObjExporterDialogController implements Initializable {
int matIndex = 0;
for (Point3i face : faces) {
// print progress
progressBar.setProgress(iprogress++/nprogress);
if (checkboxMaterial.isSelected()) {
if (count == 0) {
......@@ -253,6 +272,7 @@ public class ObjExporterDialogController implements Initializable {
}
} catch (IOException ex) {
DialogHelper.showErrorDialog(stage, new IOException("Cannot write obj file", ex));
progressBar.setProgress(0.d);
return;
}
......@@ -284,6 +304,8 @@ public class ObjExporterDialogController implements Initializable {
} catch (IOException ex) {
DialogHelper.showErrorDialog(stage, new IOException("Cannot write material file", ex));
progressBar.setProgress(0.d);
return;
}
}
......@@ -300,6 +322,7 @@ public class ObjExporterDialogController implements Initializable {
success.getDialogPane().setPrefSize(500, 200);
success.initOwner(stage);
success.showAndWait();
progressBar.setProgress(0.d);
}
private String replaceExtension(String file, String extension) {
......
......@@ -5,66 +5,72 @@
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="450.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65" fx:controller="fr.amap.lidar.amapvox.gui.export.ObjExporterDialogController">
<children>
<VBox layoutX="14.0" layoutY="29.0" spacing="20.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<VBox>
<children>
<Label text="Voxel file" />
<HBox>
<children>
<TextField fx:id="textfieldInputVoxelFile" editable="false" prefHeight="26.0" prefWidth="364.0" />
<Button mnemonicParsing="false" onAction="#onActionButtonOpenVoxelFile" text="Open" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
<VBox alignment="CENTER_LEFT" spacing="15.0">
<children>
<CheckBox fx:id="checkboxSizeFunctionOfPAD" mnemonicParsing="false" text="Size function of PAD (PAD/PADMax)^alpha" />
<HBox fx:id="hboxSizeFunctionOfPADParameters" alignment="CENTER_LEFT" spacing="10.0">
<children>
<Label text="PAD max" />
<TextField fx:id="textfieldPADMax" prefHeight="26.0" prefWidth="54.0" text="5" />
<Label text="alpha" />
<TextField fx:id="textfieldAlpha" prefHeight="26.0" prefWidth="108.0" text="0.33333333" />
</children>
<padding>
<Insets left="20.0" />
</padding>
</HBox>
</children>
</VBox>
<HBox alignment="CENTER_LEFT" spacing="20.0">
<children>
<CheckBox fx:id="checkboxMaterial" mnemonicParsing="false" selected="true" text="Write material" />
<VBox fx:id="vboxMaterialParameters" spacing="5.0">
<children>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="Attribute" />
<ComboBox fx:id="comboboxAttribute" prefHeight="26.0" prefWidth="165.0" />
</children>
<AnchorPane id="AnchorPane" prefWidth="450.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65" fx:controller="fr.amap.lidar.amapvox.gui.export.ObjExporterDialogController">
<children>
<VBox spacing="20.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" AnchorPane.bottomAnchor="10.0" fillWidth="true" >
<children>
<VBox spacing="10.0">
<children>
<Label text="Voxel file" />
<HBox spacing="10.0">
<children>
<TextField fx:id="textfieldInputVoxelFile" editable="false" prefHeight="26.0" prefWidth="400.0" />
<Button mnemonicParsing="false" onAction="#onActionButtonOpenVoxelFile" text="Open" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="Gradient" />
<ComboBox fx:id="comboboxGradient" prefHeight="26.0" prefWidth="165.0" />
</children>
</children>
</VBox>
<VBox alignment="CENTER_LEFT" spacing="15.0">
<children>
<CheckBox fx:id="checkboxSizeFunctionOfPAD" mnemonicParsing="false" text="Size function of PAD (PAD/PADMax)^alpha" />
<HBox alignment="CENTER_LEFT" spacing="10.0">
<children>
<Label text="PAD max" />
<TextField fx:id="textfieldPADMax" prefHeight="26.0" prefWidth="54.0" text="5" />
<Label text="alpha" />
<TextField fx:id="textfieldAlpha" prefHeight="26.0" prefWidth="108.0" text="0.33333333" />
</children>
<padding>
<Insets left="25.0" />
</padding>
</HBox>
</children>
</VBox>
</children>
</HBox>
</children>
</VBox>
<Button layoutX="361.0" layoutY="213.0" mnemonicParsing="false" onAction="#onActionButtonExport" text="Export" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="14.0" />
</children>
</children>
</VBox>
<HBox alignment="CENTER_LEFT" spacing="20.0">
<children>
<CheckBox fx:id="checkboxMaterial" mnemonicParsing="false" selected="true" text="Write material" />
<VBox fx:id="vboxMaterialParameters" spacing="5.0">
<children>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="Attribute" />
<ComboBox fx:id="comboboxAttribute" prefHeight="26.0" prefWidth="165.0" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="Gradient" />
<ComboBox fx:id="comboboxGradient" prefHeight="26.0" prefWidth="165.0" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
<ProgressBar fx:id="progressBar" prefHeight="18.0" progress="0.0" />
<VBox alignment="BOTTOM_RIGHT">
<Button mnemonicParsing="false" onAction="#onActionButtonExport" text="Export" />
</VBox>
</children>
</VBox>
</children>
</AnchorPane>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment