Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QcmpCompressionLibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
QcmpCompressionLibrary
Commits
5b67cd0e
Commit
5b67cd0e
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Add loadPlanesU16DataTo2dArray API to IPlaneLoader.
parent
b078632e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/cz/it4i/qcmp/io/loader/IPlaneLoader.java
+14
-0
14 additions, 0 deletions
src/main/java/cz/it4i/qcmp/io/loader/IPlaneLoader.java
src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
+46
-22
46 additions, 22 deletions
src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
with
60 additions
and
22 deletions
src/main/java/cz/it4i/qcmp/io/loader/IPlaneLoader.java
+
14
−
0
View file @
5b67cd0e
...
@@ -62,6 +62,20 @@ public interface IPlaneLoader {
...
@@ -62,6 +62,20 @@ public interface IPlaneLoader {
*/
*/
int
[]
loadPlanesU16Data
(
int
[]
planes
)
throws
IOException
;
int
[]
loadPlanesU16Data
(
int
[]
planes
)
throws
IOException
;
/**
* Load data of multiple specified planes. This functions exists, next to loadPlaneData, because some loaders
* can take advantage in loading multiple planes in one call context.
* <p>
* Data are stored in 2D array.
*
* @param planes Zero based plane indices.
* @return Planes data concatenated in single array.
* @throws IOException when fails to load plane data.
*/
default
int
[][]
loadPlanesU16DataTo2dArray
(
final
int
[]
planes
)
throws
IOException
{
throw
new
IOException
(
"Not Implemented in the current loader."
);
}
/**
/**
* Load all planes data of the image dataset.
* Load all planes data of the image dataset.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
+
46
−
22
View file @
5b67cd0e
...
@@ -15,6 +15,10 @@ import java.util.Arrays;
...
@@ -15,6 +15,10 @@ import java.util.Arrays;
public
final
class
RawDataLoader
extends
BasicLoader
implements
IPlaneLoader
{
public
final
class
RawDataLoader
extends
BasicLoader
implements
IPlaneLoader
{
private
final
FileInputData
inputDataInfo
;
private
final
FileInputData
inputDataInfo
;
private
interface
StorePlaneDataCallback
{
void
store
(
final
int
planeOffset
,
final
int
[]
planeData
);
}
public
RawDataLoader
(
final
FileInputData
inputDataInfo
)
{
public
RawDataLoader
(
final
FileInputData
inputDataInfo
)
{
super
(
inputDataInfo
.
getDimensions
());
super
(
inputDataInfo
.
getDimensions
());
this
.
inputDataInfo
=
inputDataInfo
;
this
.
inputDataInfo
=
inputDataInfo
;
...
@@ -61,51 +65,71 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader {
...
@@ -61,51 +65,71 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader {
return
TypeConverter
.
unsignedShortBytesToIntArray
(
buffer
);
return
TypeConverter
.
unsignedShortBytesToIntArray
(
buffer
);
}
}
@Override
private
void
loadPlanesU16DataImpl
(
final
int
[]
planes
,
final
StorePlaneDataCallback
storeCallback
)
throws
IOException
{
public
int
[]
loadPlanesU16Data
(
final
int
[]
planes
)
throws
IOException
{
if
(
planes
.
length
<
1
)
{
if
(
planes
.
length
<
1
)
{
return
new
int
[
0
]
;
return
;
}
else
if
(
planes
.
length
==
1
)
{
}
else
if
(
planes
.
length
==
1
)
{
return
loadPlaneData
(
planes
[
0
]);
storeCallback
.
store
(
0
,
loadPlaneData
(
planes
[
0
])
)
;
}
}
final
int
planeValueCount
=
inputDataInfo
.
getDimensions
().
getX
()
*
inputDataInfo
.
getDimensions
().
getY
();
final
int
planeValueCount
=
inputDataInfo
.
getDimensions
().
getX
()
*
inputDataInfo
.
getDimensions
().
getY
();
final
long
planeDataSize
=
2
*
(
long
)
planeValueCount
;
final
int
planeDataSize
=
2
*
planeValueCount
;
final
long
totalValueCount
=
(
long
)
planeValueCount
*
planes
.
length
;
if
(
totalValueCount
>
(
long
)
Integer
.
MAX_VALUE
)
{
throw
new
IOException
(
"Integer count is too big."
);
}
final
int
[]
values
=
new
int
[(
int
)
totalValueCount
];
final
byte
[]
planeBuffer
=
new
byte
[
planeDataSize
];
Arrays
.
sort
(
planes
);
Arrays
.
sort
(
planes
);
int
planeOffset
=
0
;
try
(
final
FileInputStream
fileStream
=
new
FileInputStream
(
inputDataInfo
.
getFilePath
());
try
(
final
FileInputStream
fileStream
=
new
FileInputStream
(
inputDataInfo
.
getFilePath
()))
{
final
DataInputStream
dis
=
new
DataInputStream
(
new
BufferedInputStream
(
fileStream
,
8192
)))
{
int
lastIndex
=
0
;
int
lastIndex
=
0
;
int
valIndex
=
0
;
for
(
final
int
planeIndex
:
planes
)
{
for
(
final
int
planeIndex
:
planes
)
{
// Skip specific number of bytes to get to the next plane.
// Skip specific number of bytes to get to the next plane.
final
int
requestedSkip
=
(
planeIndex
==
0
)
?
0
:
((
planeIndex
-
lastIndex
)
-
1
)
*
(
int
)
planeDataSize
;
final
int
requestedSkip
=
(
planeIndex
==
0
)
?
0
:
((
planeIndex
-
lastIndex
)
-
1
)
*
(
int
)
planeDataSize
;
lastIndex
=
planeIndex
;
lastIndex
=
planeIndex
;
final
int
actualSkip
=
dis
.
skipBytes
(
requestedSkip
);
final
long
actualSkip
=
fileStream
.
skip
(
requestedSkip
);
if
(
requestedSkip
!=
actualSkip
)
{
if
(
requestedSkip
!=
actualSkip
)
{
throw
new
IOException
(
"Skip operation failed."
);
throw
new
IOException
(
"Skip operation failed."
);
}
}
for
(
int
i
=
0
;
i
<
planeValueCount
;
i
++)
{
int
toRead
=
planeDataSize
;
values
[
valIndex
++]
=
dis
.
readUnsignedShort
();
while
(
toRead
>
0
)
{
final
int
read
=
fileStream
.
read
(
planeBuffer
,
planeDataSize
-
toRead
,
toRead
);
assert
(
read
>
0
);
toRead
-=
read
;
}
}
storeCallback
.
store
(
planeOffset
,
TypeConverter
.
unsignedShortBytesToIntArray
(
planeBuffer
));
++
planeOffset
;
}
}
}
}
}
return
values
;
@Override
public
int
[][]
loadPlanesU16DataTo2dArray
(
final
int
[]
planes
)
throws
IOException
{
final
int
[][]
data
=
new
int
[
planes
.
length
][];
loadPlanesU16DataImpl
(
planes
,
(
index
,
planeData
)
->
{
data
[
index
]
=
planeData
;
});
return
data
;
}
@Override
public
int
[]
loadPlanesU16Data
(
final
int
[]
planes
)
throws
IOException
{
final
int
planeValueCount
=
inputDataInfo
.
getDimensions
().
getX
()
*
inputDataInfo
.
getDimensions
().
getY
();
final
long
totalValueCount
=
(
long
)
planeValueCount
*
planes
.
length
;
if
(
totalValueCount
>
(
long
)
Integer
.
MAX_VALUE
)
{
throw
new
IOException
(
"Integer count is too big."
);
}
final
int
[]
data
=
new
int
[(
int
)
totalValueCount
];
loadPlanesU16DataImpl
(
planes
,
(
index
,
planeData
)
->
{
System
.
arraycopy
(
planeData
,
0
,
data
,
(
index
*
planeValueCount
),
planeValueCount
);
});
return
data
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment