Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
lafabregue
MultiCube
Commits
6b29f503
Commit
6b29f503
authored
Apr 07, 2017
by
lafabregue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temporary save
parent
90da2024
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
51 deletions
+118
-51
src/mustic/gui/MainFrame.java
src/mustic/gui/MainFrame.java
+1
-1
src/mustic/gui/dialog/ArffToDataDialog.java
src/mustic/gui/dialog/ArffToDataDialog.java
+18
-32
src/mustic/gui/dialog/classifier/AgentDialog.java
src/mustic/gui/dialog/classifier/AgentDialog.java
+1
-15
src/mustic/utils/io/dataExchange/DataArffExchange.java
src/mustic/utils/io/dataExchange/DataArffExchange.java
+98
-3
No files found.
src/mustic/gui/MainFrame.java
View file @
6b29f503
...
...
@@ -3395,7 +3395,7 @@ public class MainFrame extends JFrame {
}
private void toolsMenuArffToData() {
DataToArff
Dialog dialog = new
DataToArff
Dialog();
ArffToData
Dialog dialog = new
ArffToData
Dialog();
this.desktop.add(dialog);
dialog.toFront();
}
...
...
src/mustic/gui/dialog/ArffToDataDialog.java
View file @
6b29f503
...
...
@@ -9,6 +9,7 @@ import java.awt.image.BufferedImage;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.util.List
;
import
javax.imageio.ImageIO
;
import
javax.swing.JButton
;
...
...
@@ -19,6 +20,11 @@ import javax.swing.JOptionPane;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
import
jcl.data.Data
;
import
jcl.data.DataObject
;
import
jcl.data.SimpleData
;
import
mustic.utils.io.dataExchange.DataArffExchange
;
//import mustic.io.geotiff.GEOTiffImage;
/**
...
...
@@ -98,40 +104,20 @@ public class ArffToDataDialog extends JInternalFrame {
protected
void
buttonOk_actionPerformed
()
{
try
{
FileReader
fr
=
new
FileReader
(
new
File
(
this
.
textFile
.
getText
()));
BufferedReader
br
=
new
BufferedReader
(
fr
);
String
line
=
null
;
BufferedImage
buff
=
null
;
String
sdim
=
Messages
.
getString
(
"ArffToDataDialog.9"
);
//$NON-NLS-1$
while
((
line
=
br
.
readLine
())
!=
null
)
{
if
(
line
.
startsWith
(
sdim
))
{
String
dim
=
line
.
substring
(
sdim
.
length
());
String
dimension
[]
=
dim
.
split
(
","
);
//$NON-NLS-1$
int
w
=
Integer
.
parseInt
(
dimension
[
0
]);
int
h
=
Integer
.
parseInt
(
dimension
[
1
]);
buff
=
new
BufferedImage
(
w
,
h
,
BufferedImage
.
TYPE_3BYTE_BGR
);
}
else
{
String
val
[]
=
line
.
split
(
","
);
//$NON-NLS-1$
if
(
val
.
length
>=
5
)
{
int
x
=
Integer
.
parseInt
(
val
[
0
]);
int
y
=
Integer
.
parseInt
(
val
[
1
]);
buff
.
setRGB
(
x
,
y
,
(
int
)
(
Double
.
parseDouble
(
val
[
2
])*
256
*
256
+
Double
.
parseDouble
(
val
[
3
])*
256
+
Double
.
parseDouble
(
val
[
4
])));
}
}
Object
[]
result
=
DataArffExchange
.
arffToData
(
this
.
textFile
.
getText
());
if
(
result
!=
null
)
{
Data
data
=
new
SimpleData
((
List
<
DataObject
>)
result
[
1
]);
JOptionPane
.
showMessageDialog
(
this
,
Messages
.
getString
(
"ArffToDataDialog.15"
)
+
this
.
textData
.
getText
(),
Messages
.
getString
(
"ArffToDataDialog.16"
),
//$NON-NLS-1$ //$NON-NLS-2$
JOptionPane
.
INFORMATION_MESSAGE
);
}
else
{
JOptionPane
.
showMessageDialog
(
this
,
"File selected isn't supported"
,
Messages
.
getString
(
"ArffToDataDialog.4"
),
//$NON-NLS-1$ //$NON-NLS-2$
JOptionPane
.
WARNING_MESSAGE
);
}
String
name
=
this
.
textData
.
getText
();
File
outputfile
=
new
File
(
name
);
ImageIO
.
write
(
buff
,
"png"
,
outputfile
);
JOptionPane
.
showMessageDialog
(
this
,
Messages
.
getString
(
"ArffToDataDialog.15"
)
+
this
.
textData
.
getText
(),
Messages
.
getString
(
"ArffToDataDialog.16"
),
//$NON-NLS-1$ //$NON-NLS-2$
JOptionPane
.
INFORMATION_MESSAGE
);
this
.
dispose
();
}
catch
(
Exception
e
)
{
JOptionPane
.
showMessageDialog
(
this
,
...
...
src/mustic/gui/dialog/classifier/AgentDialog.java
View file @
6b29f503
...
...
@@ -142,15 +142,12 @@ public class AgentDialog extends JDialog {
DataDesktopFrame
[]
desktopFrames
=
MainFrame
.
getInstance
().
getDesktop
().
getAllDataDesktopFrames
();
int
nbSessions
=
desktopFrames
.
length
;
//TODO
if
(
nbSessions
>
0
&&
this
.
classifierPanel
.
getApproachPanel
().
getDataComboBox
().
getSelectedIndex
()
<=
nbSessions
//&& this.classifierPanel.getApproachPanel().getMonodateRadioButton().isSelected()
)
{
int
index
=
this
.
classifierPanel
.
getApproachPanel
().
getDataComboBox
().
getSelectedIndex
();
if
(
index
<
nbSessions
)
{
// choix de données existantes
DataSession
img
=
desktopFrames
[
this
.
classifierPanel
.
getApproachPanel
().
getDataComboBox
().
getSelectedIndex
()].
getDataSession
();
...
...
@@ -158,18 +155,7 @@ public class AgentDialog extends JDialog {
this
.
imgdata
=
(
ImageData
)
img
.
getData
();
this
.
imgdata
.
setDataFilesName
(
imgdata
.
getDataFilesName
());
}
else
if
(
index
==
nbSessions
)
{
// séquence d'images TODO : sortir
DataSession
img
=
desktopFrames
[
this
.
classifierPanel
.
sequenceDialog
.
getFirstIndex
()].
getDataSession
();
this
.
imgdata
=
img
.
getData
();
try
{
this
.
imgdata
.
setSequence
(
this
.
classifierPanel
.
sequenceDialog
.
getSequenceData
());
}
catch
(
FormatException
e1
)
{
e1
.
printStackTrace
();
}
}
}
/*
*
...
...
src/mustic/utils/io/dataExchange/DataArffExchange.java
View file @
6b29f503
package
mustic.utils.io.dataExchange
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
jcl.data.Data
;
import
jcl.data.DataObject
;
import
jcl.data.attribute.AttributeMultiDimSequence
;
import
jcl.data.attribute.AttributeNumerical
;
import
jcl.data.attribute.AttributeSequence
;
import
jcl.data.attribute.AttributeSymbolicCategorial
;
import
weka.core.Attribute
;
import
weka.core.DenseInstance
;
import
weka.core.Instance
;
import
weka.core.Instances
;
import
weka.core.converters.ArffLoader.ArffReader
;
/**
* Class to import/export ARFF files from/to Data objects
* Class to import/export ARFF files from/to Data objects.
* This implementation is not exhaustive. It is designed to handle images
* with multi-mono temporal formats, but it might be used/extended for other cases.
*
* The import format is based on the export one, so some incompatibilities might occurs.
*
* @author Baptiste LAFABREGUE
*
*/
public
class
DataArffExchange
{
/**
* Write a Data into a file in respect of the arff format
*
* @param path
* the path of the file to write
* @param data
* the data to write
*/
public
static
void
dataToArff
(
String
path
,
Data
data
)
{
System
.
out
.
println
(
"__________________________________________________________________________________________\n"
);
//$NON-NLS-1$
System
.
out
.
println
(
"Write \""
+
data
.
getDataName
()+
"\" to file : "
+
path
);
//$NON-NLS-1$
...
...
@@ -76,10 +95,86 @@ public class DataArffExchange {
}
}
public
static
DataObject
[]
arffToData
(
String
path
)
{
return
null
;
/**
* Return a set of DataObjects that is stored in an arff file.
* The file should respect only one additional format constraint,
* that the first attribute is the index.
*
* @param path
* the path of the arff file
* @return an Object array of size two :
* - at index 0 : the set on indexes (List<Integer>)
* - at index 1 : the set of DataObjects (List<DataObject>)
*/
public
static
Object
[]
arffToData
(
String
path
)
{
System
.
out
.
println
(
"__________________________________________________________________________________________\n"
);
//$NON-NLS-1$
System
.
out
.
println
(
"Read \""
+
path
+
"\" to new Data "
);
//$NON-NLS-1$
System
.
out
.
println
(
"__________________________________________________________________________________________"
);
//$NON-NLS-1$
Object
[]
result
=
new
Object
[
2
];
List
<
DataObject
>
dataObjects
=
new
ArrayList
<
DataObject
>();
List
<
Integer
>
indexes
=
new
ArrayList
<
Integer
>();
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
new
File
(
path
)));
ArffReader
arff
=
new
ArffReader
(
reader
,
1000
);
Instances
data
=
arff
.
getStructure
();
data
.
setClassIndex
(
0
);
Instance
inst
;
while
((
inst
=
arff
.
readInstance
(
data
))
!=
null
)
{
DataObject
obj
=
new
DataObject
(
inst
.
numAttributes
()
-
1
);
// the first attribute is ignored because it is the index
for
(
int
i
=
1
;
i
<
inst
.
numAttributes
()
;
i
++)
{
obj
.
setAttribute
(
i
-
1
,
getAttribute
(
inst
,
i
));
}
dataObjects
.
add
(
obj
);
indexes
.
add
((
int
)
inst
.
value
(
0
));
}
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
result
[
0
]
=
indexes
;
result
[
1
]
=
dataObjects
;
return
result
;
}
private
static
jcl
.
data
.
attribute
.
Attribute
getAttribute
(
Instance
inst
,
int
index
)
{
switch
(
inst
.
attribute
(
index
).
type
())
{
case
Attribute
.
NUMERIC
:
return
new
AttributeNumerical
(
inst
.
value
(
index
));
case
Attribute
.
STRING
:
return
new
AttributeSymbolicCategorial
(
inst
.
stringValue
(
index
));
case
Attribute
.
RELATIONAL
:
if
(
inst
.
attribute
(
index
).
relation
().
numAttributes
()
>
0
&&
inst
.
attribute
(
index
).
relation
().
attribute
(
0
).
isRelationValued
())
{
// MultiDimSequence case, where we have a sub relation in the relation
double
[][]
seq
=
new
double
[
inst
.
attribute
(
index
).
relation
().
numAttributes
()][];
for
(
int
i
=
0
;
i
<
inst
.
attribute
(
index
).
relation
().
numAttributes
()
;
i
++)
{
Instances
instances
=
inst
.
relationalValue
(
index
);
seq
[
i
]
=
new
double
[
instances
.
attribute
(
0
).
relation
().
numAttributes
()];
for
(
int
j
=
0
;
j
<
instances
.
attribute
(
0
).
relation
().
numAttributes
()
;
j
++)
{
seq
[
i
][
j
]
=
instances
.
get
(
j
).
value
(
0
);
}
}
return
new
AttributeMultiDimSequence
(
seq
);
}
else
{
// Sequence case, where we only one relation layer
double
[]
seq
=
new
double
[
inst
.
attribute
(
index
).
relation
().
numAttributes
()];
for
(
int
i
=
0
;
i
<
inst
.
attribute
(
index
).
relation
().
numAttributes
()
;
i
++)
{
seq
[
i
]
=
inst
.
value
(
i
);
}
return
new
AttributeSequence
(
seq
);
}
}
return
null
;
}
private
static
double
getArffInstance
(
jcl
.
data
.
attribute
.
Attribute
attr
,
Instances
arffData
,
int
attrIndex
)
{
if
(
attr
instanceof
AttributeSequence
)
{
Instances
sequence
=
new
Instances
(
arffData
.
attribute
(
attrIndex
).
relation
(),
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment