Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DicomTile {
public Double zOffset;
public int channel;
public boolean last = false;
public int planeIndex = -1;

public boolean isJP2K = false;
public boolean isJPEG = false;
Expand Down
59 changes: 43 additions & 16 deletions components/formats-bsd/src/loci/formats/in/DicomReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public int getTileColumns(int no) {
public byte[] openCompressedBytes(int no, int x, int y) throws FormatException, IOException {
FormatTools.assertId(currentId, true, 1);

// TODO: this will result in a lot of redundant lookups, and should be optimized
int tileWidth = getOptimalTileWidth();
int tileHeight = getOptimalTileHeight();
Region boundingBox = new Region(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
Expand Down Expand Up @@ -860,7 +859,7 @@ else if (child.attribute == OPTICAL_PATH_DESCRIPTION) {

for (int p=0; p<imagesPerFile; p++) {
DicomTile tile = new DicomTile();
tile.fileIndex = tilePositions.get(0).size();
tile.fileIndex = getTiles(0).size();
if (m.sizeZ == 1 && fileZOffset != null) {
tile.zOffset = fileZOffset;
}
Expand Down Expand Up @@ -1070,6 +1069,13 @@ else if (info.concatenationIndex == 0) {

watch.start();

int currentCoreIndex = getCoreIndex();
for (Integer key : tilePositions.keySet()) {
setCoreIndex(key);
calculateTilePlaneIndexes();
}
setCoreIndex(currentCoreIndex);

// The metadata store we're working with.
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
Expand Down Expand Up @@ -1707,25 +1713,18 @@ private CodecOptions getTileCodecOptions(DicomTile tile) {
* If the "firstTileOnly" flag is set, then this will return as soon
* as one matching tile is found.
*/
private List<DicomTile> getTileList(int no, Region boundingBox, boolean firstTileOnly) {
int z = getZCTCoords(no)[0];
int c = getZCTCoords(no)[1];

public List<DicomTile> getTileList(int no, Region boundingBox, boolean firstTileOnly) {
List<DicomTile> tileList = new ArrayList<DicomTile>();
if (!tilePositions.containsKey(getCoreIndex())) {
LOGGER.warn("No tiles for core index = {}", getCoreIndex());
return tileList;
}

// look for any tiles that match the requested tile and plane
List<Double> zs = zOffsets.get(getCoreIndex());
List<DicomTile> tiles = tilePositions.get(getCoreIndex());
for (int t=0; t<tiles.size(); t++) {
DicomTile tile = tiles.get(t);
if ((getSizeZ() == 1 || (getSizeZ() <= zs.size() && tile.zOffset.equals(zs.get(z))) || (getSizeZ() == tiles.size() && t == z)) &&
(tile.channel == c || getEffectiveSizeC() == 1) &&
(boundingBox == null || tile.region.intersects(boundingBox)))
{
for (DicomTile tile : getTiles(getCoreIndex())) {
boolean inBoundingBox = boundingBox == null || tile.region.intersects(boundingBox);
boolean validPlane = tile.planeIndex == no;
if (validPlane && inBoundingBox) {
tileList.add(tile);
if (firstTileOnly) {
break;
Expand All @@ -1741,6 +1740,23 @@ private List<DicomTile> getTileList(int no, Region boundingBox, boolean firstTil
return tileList;
}

private void calculateTilePlaneIndexes() {
List<Double> zs = zOffsets.get(getCoreIndex());
List<DicomTile> tiles = getTiles(getCoreIndex());
for (int t=0; t<tiles.size(); t++) {
DicomTile tile = tiles.get(t);
for (int p=0; p<getImageCount(); p++) {
int[] zct = getZCTCoords(p);
boolean validZ = getSizeZ() == 1 || (getSizeZ() <= zs.size() && tile.zOffset.equals(zs.get(zct[0]))) || (getSizeZ() == tiles.size() && t == zct[0]);
boolean validC = tile.channel == zct[1] || getEffectiveSizeC() == 1;
if (validZ && validC) {
tile.planeIndex = p;
break;
}
}
}
}

/**
* Decompress pixel data associated with the given DicomTile.
*/
Expand Down Expand Up @@ -2108,11 +2124,22 @@ public String getImageType() {
}

public List<DicomTile> getTiles() {
return tilePositions.get(0);
return getTiles(0);
}

public List<DicomTile> getTiles(int coreIndex) {
if (tilePositions.containsKey(coreIndex)) {
return tilePositions.get(coreIndex);
}
return new ArrayList<DicomTile>();
}

public List<Double> getZOffsets() {
return zOffsets.get(0);
return getZOffsets(0);
}

public List<Double> getZOffsets(int coreIndex) {
return zOffsets.get(coreIndex);
}

public int getConcatenationIndex() {
Expand Down
Loading