Add the panel to display image source previews.
authorGreg Burri <greg.burri@gmail.com>
Fri, 8 Jan 2016 12:25:17 +0000 (13:25 +0100)
committerGreg Burri <greg.burri@gmail.com>
Fri, 8 Jan 2016 12:25:17 +0000 (13:25 +0100)
Parasitemia/Parasitemia/GUI/GUI.fs
Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml [new file with mode: 0644]
Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs [new file with mode: 0644]
Parasitemia/Parasitemia/GUI/MainWindow.xaml
Parasitemia/Parasitemia/GUI/State.fs
Parasitemia/Parasitemia/Parasitemia.fsproj
Parasitemia/WPF/WPF.csproj

index cf7ed67..155c1d1 100644 (file)
@@ -10,8 +10,8 @@ open System.Drawing
 open System.Diagnostics
 open Microsoft.Win32 // For the common dialogs.
 
-open Emgu.CV
-open Emgu.CV.Structure
+//open Emgu.CV
+//open Emgu.CV.Structure
 open Emgu.CV.WPF
 
 open Config
@@ -26,21 +26,38 @@ let run (defaultConfig: Config) =
 
     let state = State.State()
 
-    let exit: Controls.MenuItem = ctrl "menuExit"
-    let save: Controls.MenuItem = ctrl "menuSave"
-    let load: Controls.MenuItem = ctrl "menuOpen"
+    let exit: MenuItem = ctrl "menuExit"
+    let saveFile: MenuItem = ctrl "menuSave"
+    let loadFile: MenuItem = ctrl "menuOpen"
+    let newFile: MenuItem = ctrl "menuNew"
 
-    let txtPatient: Controls.TextBox = ctrl "txtPatient"
+    let addSourceImage: MenuItem = ctrl "menuAddSourceImage"
 
+    let txtPatient: TextBox = ctrl "txtPatient"
+
+    let stackPreviews: StackPanel = ctrl "stackPreviews"
+
+    let butStartAnalysis: Button = ctrl "butStartAnalysis"
 
     let synchronizeState () =
         state.PatientID <- txtPatient.Text
 
-    let synchronizeView () =
+    let updatePreviews () =
+        stackPreviews.Children.Clear ()
+        state.ImagesSource |> Seq.iteri (fun i imgSrc ->
+            let imgCtrl = Views.ImageSourcePreview(Margin = Thickness(3.))
+            imgCtrl.lblImageNumber.Content <- i + 1
+            let width = 200
+            let height = imgSrc.img.Height * width / imgSrc.img.Width
+            imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(imgSrc.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
+            stackPreviews.Children.Add(imgCtrl) |> ignore )
+
+    let updateGUI () =
         txtPatient.Text <- state.PatientID
+        updatePreviews ()
 
     exit.Click.AddHandler(fun obj args -> mainWindow.Root.Close())
-    save.Click.AddHandler(fun obj args ->
+    saveFile.Click.AddHandler(fun obj args ->
         synchronizeState ()
         if state.FilePath = ""
         then
@@ -53,7 +70,7 @@ let run (defaultConfig: Config) =
         else
             state.Save())
 
-    load.Click.AddHandler(fun obj args ->
+    loadFile.Click.AddHandler(fun obj args ->
         // TODO: if current state not saved and not empty, ask to save it.
         let dialog = OpenFileDialog(Filter = Pia.filter)
         let res = dialog.ShowDialog()
@@ -61,7 +78,22 @@ let run (defaultConfig: Config) =
         then
             state.FilePath <- dialog.FileName
             state.Load()
-            synchronizeView ())
+            updateGUI ())
+
+    newFile.Click.AddHandler(fun obj args ->
+        // TODO: if current state not saved and not empty, ask to save it.
+        state.Reset()
+        updateGUI())
+
+    addSourceImage.Click.AddHandler(fun obj args ->
+        let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff")
+        let res = dialog.ShowDialog()
+        if res.HasValue && res.Value
+        then
+            state.AddSourceImage(dialog.FileName)
+            updatePreviews ())
+
+    butStartAnalysis.Click.AddHandler(fun obj args -> ())
 
     (*let txtPatient: Controls.TextBox = ctrl "txtPatient"
     txtPatient.TextChanged.AddHandler(fun obj args ->
diff --git a/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml
new file mode 100644 (file)
index 0000000..3593e0e
--- /dev/null
@@ -0,0 +1,13 @@
+<UserControl
+               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+      xmlns:fsxaml="clr-namespace:FsXaml;assembly=FsXaml.Wpf"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+      mc:Ignorable="d" d:DesignWidth="119.223" d:DesignHeight="84.911"
+               >
+   <Grid>
+      <Image x:Name="imagePreview" />
+      <Label x:Name="lblImageNumber" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#4C000000" Foreground="White"/>
+   </Grid>
+</UserControl>
\ No newline at end of file
diff --git a/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs
new file mode 100644 (file)
index 0000000..b92e9af
--- /dev/null
@@ -0,0 +1,17 @@
+namespace Parasitemia.Views
+
+open System
+open System.Windows
+open System.Windows.Data
+open System.Windows.Input
+
+open FSharp.ViewModule
+open FsXaml
+
+type ImageSourcePreview = XAML<"GUI/ImageSourcePreview.xaml", true>
+
+(* type ImageSourcePreviewController() =
+    inherit UserControlViewController<ImageSourcePreview>() *)
+
+(* type ImageSourcePreviewViewModel() =
+    inherit ViewModelBase() *)
index 5b7a3c5..2892330 100644 (file)
@@ -9,6 +9,9 @@
             <Separator />
             <MenuItem x:Name="menuExit" Header="_Exit" />
          </MenuItem>
+         <MenuItem Header="_Images">
+            <MenuItem x:Name="menuAddSourceImage" Header="_Add a source image" />
+         </MenuItem>
       </Menu>
 
       <Grid x:Name="gridMain">
@@ -17,8 +20,8 @@
             <RowDefinition/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="130"/>
             <ColumnDefinition/>
-            <ColumnDefinition Width="5*"/>
          </Grid.ColumnDefinitions>
          <Grid x:Name="gridGlobalInfo" Grid.ColumnSpan="2" Margin="3,3,3,3" >
             <Grid.ColumnDefinitions>
             <TextBox x:Name="txtPatient" Grid.Column="1" Margin="3, 3, 10, 3" TextWrapping="Wrap" VerticalAlignment="Center" />
             <TextBox x:Name="txtGlobalParasitemia" Grid.Column="1" Grid.Row="2" Margin="3, 3, 10, 3" TextWrapping="Wrap" VerticalAlignment="Center" IsReadOnly="True" />
          </Grid>
+         <Border BorderBrush="Black" BorderThickness="1"  Grid.Row="1" Margin="3">
+            <Grid>
+               <Grid.RowDefinitions>
+                  <RowDefinition/>
+                  <RowDefinition Height="Auto" />
+               </Grid.RowDefinitions>
+               <ScrollViewer x:Name="scrollPreviews" VerticalScrollBarVisibility="Auto" Margin="0,0,0,1" Grid.Row="1" >
+                  <StackPanel x:Name="stackPreviews" />
+               </ScrollViewer>
+               <Button x:Name="butStartAnalysis" Content="Start analysis" Grid.Row="1"/>
+            </Grid>
+         </Border>
       </Grid>
    </DockPanel>
 </Window>
\ No newline at end of file
index a4a1773..b5136c2 100644 (file)
@@ -2,8 +2,15 @@
 
 open System.Collections.Generic
 
+open Emgu.CV
+open Emgu.CV.Structure
+
+type ImageSource = {
+    cells: List<Types.Cell>
+    img: Image<Bgr, byte> }
+
 type State () =
-    let cells = List<Types.Cell>()
+    let imagesSource = List<ImageSource>()
 
     member val FilePath: string = "" with get, set
     member val PatientID: string = "" with get, set
@@ -14,4 +21,14 @@ type State () =
 
     member this.Load () =
         let data = Pia.load this.FilePath
-        this.PatientID <- data.patientID
\ No newline at end of file
+        this.PatientID <- data.patientID
+
+    member this.AddSourceImage (filePath: string) =
+        imagesSource.Add({ cells = List<Types.Cell>(); img = new Image<Bgr, byte>(filePath) })
+
+    member x.ImagesSource : ImageSource seq =
+        imagesSource :> ImageSource seq
+
+    member this.Reset () =
+        this.PatientID <- ""
+        imagesSource.Clear()
\ No newline at end of file
index abdb475..840a8f8 100644 (file)
     <Compile Include="Ellipse.fs" />
     <Compile Include="Classifier.fs" />
     <Compile Include="MainAnalysis.fs" />
-    <None Include="GUI\NumericUpDown.xaml" />
+    <Resource Include="GUI\NumericUpDown.xaml" />
     <Compile Include="GUI\NumericUpDown.xaml.fs" />
+    <Resource Include="GUI\ImageSourcePreview.xaml" />
+    <Compile Include="GUI\ImageSourcePreview.xaml.fs" />
     <Resource Include="GUI\MainWindow.xaml" />
     <Compile Include="GUI\MainWindow.xaml.fs" />
     <Compile Include="GUI\Pia.fs" />
index 66a9cc9..77830ee 100644 (file)
@@ -20,6 +20,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <UseVSHostingProcess>true</UseVSHostingProcess>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>