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
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
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()
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 ->
--- /dev/null
+<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
--- /dev/null
+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() *)
<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">
<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
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
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
<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" />
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>