Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mzouink committed Jun 23, 2020
1 parent 3e1417f commit 06d67cd
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/preibisch/pinna2d/tools/Imp.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public float getMax() {
return max.get();
}

public void save(@NotNull File file) {
public boolean save(@NotNull File file) {
int dims = img.numDimensions() - 1;
IntervalView<FloatType> view = Views.hyperSlice(img, dims, categoryChannel);
save(view, file);
return save(view, file);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/preibisch/pinna2d/utils/ImpHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ public static <T extends FloatType> void computeMinMax(

}

public static void save(IntervalView<FloatType> view, File file) {
public static boolean save(IntervalView<FloatType> view, File file) {
ImagePlus imp = ImageJFunctions.wrap(view, "Categories");
imp.show();
saveTiffStack(imp, file);
return saveTiffStack(imp, file);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.preibisch.pinna2d.model.toAnnotationEntry
import com.preibisch.pinna2d.tools.Imp
import com.preibisch.pinna2d.tools.Log
import com.preibisch.pinna2d.util.execute
import com.preibisch.pinna2d.util.showPopup
import com.preibisch.pinna2d.util.toDate
import javafx.collections.FXCollections
import javafx.collections.ObservableList
Expand Down Expand Up @@ -36,21 +37,22 @@ class AnnotationController : Controller() {
items = FXCollections.observableArrayList();
}

fun add(newEntryDate: LocalDate, newImageName: String, newAnnotationId: Float, newAnnotationVal: Int, spaceVal: Long): AnnotationEntry {
fun add(newImageId: Int,newEntryDate: LocalDate, newImageName: String, newAnnotationId: Float, newAnnotationVal: Int, spaceVal: Long): AnnotationEntry {
val newEntry = execute {
AnnotationEntryTbl.insert {
it[entryDate] = newEntryDate.toDate()
it[imageId] = newImageId
it[imageName] = newImageName
it[annotationId] = newAnnotationId
it[annotationVal] = newAnnotationVal
it[spaceDims] = spaceVal
}
}
items.add(AnnotationEntryModel().apply {
item = AnnotationEntry(newEntry[AnnotationEntryTbl.id], newEntryDate, newImageName, newAnnotationId, newAnnotationVal, spaceVal)
item = AnnotationEntry(newEntry[AnnotationEntryTbl.id], newEntryDate, newImageId,newImageName, newAnnotationId, newAnnotationVal, spaceVal)
})
// pieItemsData.add(PieChart.Data(newItem,newPrice))
return AnnotationEntry(newEntry[AnnotationEntryTbl.id], newEntryDate, newImageName, newAnnotationId, newAnnotationVal, spaceVal)
return AnnotationEntry(newEntry[AnnotationEntryTbl.id], newEntryDate, newImageId, newImageName, newAnnotationId, newAnnotationVal, spaceVal)
}

fun update(updatedItem: AnnotationEntryModel): Int {
Expand All @@ -77,20 +79,20 @@ class AnnotationController : Controller() {
// removeModelFromPie(model)
}

private fun newEntry(img: String, min: Int, max: Int) {
private fun newEntry(imageId: Int, img: String, min: Int, max: Int) {
for (i in min..max) {
add(LocalDate.now(), img, i.toFloat(), -1, 0)
add(imageId,LocalDate.now(), img, i.toFloat(), -1, 0)

}
}

fun start(projectFolder: String, imageName: String, min: Float, max: Float) {
fun start(imageId: Int, projectFolder: String, imageName: String, min: Float, max: Float) {
folder = projectFolder
currentImage = imageName
items.clear()
val exists = checkExist(imageName)
if (!exists)
newEntry(imageName, min.toInt(), max.toInt())
newEntry(imageId, imageName, min.toInt(), max.toInt())
else {
val newItems = execute {
AnnotationEntryTbl.select { AnnotationEntryTbl.imageName eq imageName }.map {
Expand Down Expand Up @@ -148,7 +150,8 @@ class AnnotationController : Controller() {
fun exportStatistics() {
val basename = currentImage.split(".")[0]
val f = File(folder, String.format("%s.csv", basename))
f.toAnnotationCSV(items)
val result = f.toAnnotationCSV(items)
showPopup(result,"Saving CSV file!",f.path)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javafx.collections.ObservableList
import java.io.File
import java.io.FileWriter

fun File.toAnnotationCSV(list: ObservableList<AnnotationEntryModel>) {
fun File.toAnnotationCSV(list: ObservableList<AnnotationEntryModel>): Boolean {
try {
var fileWriter = FileWriter(this)
val head = String.format("%s,%s,%s", AnnotationEntryModel::annotationId.name, AnnotationEntryModel::annotationVal.name, AnnotationEntryModel::spaceDims.name)
Expand All @@ -17,9 +17,12 @@ fun File.toAnnotationCSV(list: ObservableList<AnnotationEntryModel>) {
}
fileWriter.flush()
fileWriter.close()
return true
} catch (e: Exception) {
Log.error("Error writing file !")
Log.error(e.toString())
return false
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class FilesAnalyzeManager : Controller() {
assembledData.forEach { (t, u) ->
if (!checkExist(t.name, listOfItems)) {
val bestMask = getMaxCells(u)
add(LocalDate.now(), t.name, bestMask.name, u.size, getNbCells(bestMask), 0, 0)
val status = if (u.isNotEmpty()) 0 else 1
add(LocalDate.now(), t.name, bestMask.name, u.size, getNbCells(bestMask), 0, status)
}
}

Expand All @@ -70,10 +71,21 @@ class FilesAnalyzeManager : Controller() {
return ImageEntry(newEntry[ImageEntryTbl.id], newEntryDate, newImageName, newMaskFile, newNbMasks, newNbCells, newNbClassifiedCells, newStatus)
}

fun updateStatus(id: Int, newStatus: Int){
return execute {
ImageEntryTbl.update({
AnnotationEntryTbl.id eq (id)
}) {
it[status] = newStatus
}
}

}

fun update(updatedItem: ImageEntryModel): Int {
return execute {
ImageEntryTbl.update({
AnnotationEntryTbl.id eq (updatedItem.id.value.toInt())
ImageEntryTbl.id eq (updatedItem.id.value.toInt())
}) {
it[entryDate] = updatedItem.entryDate.value.toDate()
it[fileName] = updatedItem.fileName.value
Expand Down Expand Up @@ -112,5 +124,19 @@ class FilesAnalyzeManager : Controller() {
val elms = maskFile.name.split(".")[0].split("_")
return elms.last().toInt()
}

fun startedImage(name: String) {
val newStatus = 1
for (f in files){
if (f.fileName.value == name){
Log.info("Update id: ${f.id.value}")
f.status.value = newStatus
update(f)
break
}
}


}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.preibisch.pinna2d.controllers
import com.preibisch.pinna2d.model.AnnotationEntryModel
import com.preibisch.pinna2d.tools.Imp
import com.preibisch.pinna2d.tools.Log
import com.preibisch.pinna2d.util.showPopup
import javafx.beans.property.SimpleStringProperty
import javafx.geometry.Point2D
import javafx.scene.Node
Expand Down Expand Up @@ -63,7 +64,8 @@ class ImageController : Controller() {
}

fun save(file: File) {
Imp.get().save(file)
val result = Imp.get().save(file)
showPopup(result,"Saving file!",file.path)
}

fun select(v: Float) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package com.preibisch.pinna2d.controllers

import com.preibisch.pinna2d.tools.Imp
import com.preibisch.pinna2d.view.MainAnnotationView
import tornadofx.*
import java.io.File

class InstanceController : Controller() {

val annotationController: AnnotationController by inject()
val fileController: FilesAnalyzeManager by inject()
private val imageController: ImageController by inject()

private var projectPath = ""
var inputPath: String = ""
var maskPath: String = ""
var imageName: String = ""

fun start(projectFolder : String, inputPath: String, maskPath: String) {
fun start(imageId: Int, projectFolder: String, inputPath: String, maskPath: String) {
this.projectPath = projectFolder
this.inputPath = inputPath
this.maskPath = maskPath
this.imageName = File(inputPath).name
println(imageName)
imageController.start(inputPath, maskPath,imageName)
annotationController.start(projectPath,imageName, Imp.get().min+1, Imp.get().max)
fileController.startedImage(imageName)
annotationController.start(imageId,projectPath,imageName, Imp.get().min+1, Imp.get().max)


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.time.LocalDate
fun ResultRow.toAnnotationEntry() = AnnotationEntry(
this[AnnotationEntryTbl.id],
this[AnnotationEntryTbl.entryDate].toJavaLocalDate(),
this[AnnotationEntryTbl.imageId].toInt(),
this[AnnotationEntryTbl.imageName],
this[AnnotationEntryTbl.annotationId].toFloat(),
this[AnnotationEntryTbl.annotationVal].toInt(),
Expand All @@ -19,16 +20,20 @@ fun ResultRow.toAnnotationEntry() = AnnotationEntry(
object AnnotationEntryTbl : Table() {
val id = integer(id_string).autoIncrement().primaryKey()
val entryDate = date(entry_date)
val imageId = integer(image_id)
val imageName = varchar(image_name, length = 100)
val annotationId = float(annotation_id)
val annotationVal = integer(annotation_val)
val spaceDims = long(space_dims)
}

class AnnotationEntry(id: Int, entryDate: LocalDate, imageName: String, annotationId: Float, annotationVal : Int, spaceVal: Long) {
class AnnotationEntry(id: Int, entryDate: LocalDate, imageId: Int, imageName: String, annotationId: Float, annotationVal : Int, spaceVal: Long) {
val idProperty = SimpleIntegerProperty(id)
var id by idProperty

val imageIdProperty = SimpleIntegerProperty(imageId)
var imageId by imageIdProperty

val entryDateProperty = SimpleObjectProperty<LocalDate>(entryDate)
var entryDate by entryDateProperty

Expand All @@ -52,6 +57,7 @@ class AnnotationEntry(id: Int, entryDate: LocalDate, imageName: String, annotati
class AnnotationEntryModel : ItemViewModel<AnnotationEntry>() {
val id = bind { item?.idProperty }
val entryDate = bind { item?.entryDateProperty }
val imageId = bind { item?.imageIdProperty }
val imageName = bind { item?.imageNameProperty }
val annotationId = bind { item?.annotationIdProperty }
val annotationVal = bind { item?.annotationValProperty }
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/preibisch/pinna2d/util/FileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.preibisch.pinna2d.util
import com.preibisch.pinna2d.tools.Log


private val statusList: List<String> = listOf("Not stated Yet","No Masks","Started","Finished")
private val statusList: List<String> = listOf("Not stated Yet","Started","No Masks","Finished")

fun getStatus(statusCode: Int) : String{
if((statusCode)>= statusList.size){
Expand Down
28 changes: 28 additions & 0 deletions src/main/kotlin/com/preibisch/pinna2d/util/IOFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.preibisch.pinna2d.util

import com.preibisch.pinna2d.tools.Log
import javafx.scene.control.Alert
import javafx.scene.control.Alert.AlertType
import javafx.scene.control.ButtonType
import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
import javafx.stage.Window
import tornadofx.*
import java.io.File
import java.io.IOException


fun assembleInputWithMasks(inputFiles: Array<File>, maskFiles: Array<File>): Map<File, List<File>> {
var result = HashMap<File, List<File>>()
inputFiles.forEach {
Expand Down Expand Up @@ -40,4 +47,25 @@ fun openFolderChooser(): String {
var chooser = DirectoryChooser()
val file = chooser.showDialog(null)
return file?.toString() ?: ""
}

fun imageSaverBox(currentWindow: Window?): File? {
Log.info("save")
var chooser = FileChooser()
val name = String.format("%s_instances.tif", CURRENT_IMAGE.split(".")[0])
chooser.initialDirectory = File(PROJECT_FOLDER)
chooser.initialFileName = name
chooser.extensionFilters.add(FileChooser.ExtensionFilter("TIF file ", "*.tif"))
chooser.extensionFilters.add(FileChooser.ExtensionFilter("TIFF file ", "*.tiff"))
chooser.extensionFilters.add(FileChooser.ExtensionFilter("PNG file ", "*.png"))
val file = chooser.showSaveDialog(currentWindow)
Log.info(file.toString())
return file
}

fun showPopup(condition: Boolean,title: String, msg: String){
if (condition)
information(title,msg)
else
error(title,msg)
}
1 change: 1 addition & 0 deletions src/main/kotlin/com/preibisch/pinna2d/util/Names.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.preibisch.pinna2d.util
//DB Images
const val id_string = "id"
const val entry_date = "entry_date"
const val image_id = "image_id"
const val image_name = "image_name"
const val mask_file = "mask_file"
const val nb_masks = "nb_masks"
Expand Down
20 changes: 16 additions & 4 deletions src/main/kotlin/com/preibisch/pinna2d/view/AnnotationEditorView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.preibisch.pinna2d.controllers.AnnotationController
import com.preibisch.pinna2d.controllers.ImageController
import com.preibisch.pinna2d.model.AnnotationEntryModel
import com.preibisch.pinna2d.tools.Imp
import com.preibisch.pinna2d.util.CATEGORIES
import com.preibisch.pinna2d.util.getColor
import com.preibisch.pinna2d.util.*
import javafx.scene.control.ToggleButton
import javafx.scene.control.ToggleGroup
import javafx.scene.paint.Color
import javafx.scene.shape.Circle
import tornadofx.*
import java.io.File

class AnnotationEditorView : View("Annotations") {

Expand Down Expand Up @@ -79,13 +79,25 @@ class AnnotationEditorView : View("Annotations") {
}

}
borderpane { right = button("Export Statistics") {
button("Export Statistics") {
prefWidth = 220.0
setOnAction { controller.exportStatistics() }
} }
}
button("Save Instance Image") {
prefWidth = 220.0
setOnAction { save() }
}


}
}

private fun save(){
val file = imageSaverBox(this.currentWindow)
if (file.toString() != null)
imageController.save(File(file.toString()))
}

private fun generateCategoriesButtons() {
val group = ToggleGroup()
for (cat in CATEGORIES)
Expand Down
Loading

0 comments on commit 06d67cd

Please sign in to comment.