Skip to content

Commit

Permalink
One more fix for channels that are acquired in more than one action
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Aug 31, 2023
1 parent 6058cec commit 48c1baf
Showing 1 changed file with 52 additions and 16 deletions.
68 changes: 52 additions & 16 deletions components/formats-gpl/src/loci/formats/in/CV7000Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,6 @@ protected void initFile(String id) throws FormatException, IOException {
if (settingsPath != null) {
settingsPath = new Location(parent, settingsPath).getAbsolutePath();
}

channels.sort(new Comparator<Channel>() {
@Override
public int compare(Channel c1, Channel c2) {
return c1.index - c2.index;
}
});
}

if (settingsPath != null && new Location(settingsPath).exists()) {
Expand All @@ -325,6 +318,16 @@ public int compare(Channel c1, Channel c2) {
}
}

channels.sort(new Comparator<Channel>() {
@Override
public int compare(Channel c1, Channel c2) {
if (c1.actionIndex != c2.actionIndex) {
return c1.actionIndex - c2.actionIndex;
}
return c1.index - c2.index;
}
});

for (Channel ch : channels) {
if (ch.correctionFile != null) {
ch.correctionFile = new Location(parent, ch.correctionFile).getAbsolutePath();
Expand Down Expand Up @@ -582,7 +585,7 @@ public int compare(Channel c1, Channel c2) {
// particular plane. Skip it.
continue;
}
Channel channel = lookupChannel(p.channel);
Channel channel = lookupChannel(p);
if (channel == null) {
continue;
}
Expand All @@ -607,7 +610,7 @@ public int compare(Channel c1, Channel c2) {

// the index here is the original bts:Ch index in
// the *.mes and *.mrf files
store.setChannelName("Action #" + (channel.actionIndex + 1) +
store.setChannelName("Action #" + (p.actionIndex + 1) +
", Channel #" + (channel.index + 1) + ", Camera #" + channel.cameraNumber, i, c);

if (channel.color != null) {
Expand Down Expand Up @@ -669,7 +672,7 @@ private int getChannelIndex(Plane p) {
ch.actionIndex == action)
{
index++;
if (ch.index == p.channel) {
if (ch.index == p.channel && ch.actionIndex == p.actionIndex) {
return index;
}
}
Expand All @@ -678,9 +681,9 @@ private int getChannelIndex(Plane p) {
return index;
}

private Channel lookupChannel(int index) {
private Channel lookupChannel(Plane p) {
for (Channel ch : channels) {
if (ch.index == index) {
if (ch.index == p.channel) {
return ch;
}
}
Expand Down Expand Up @@ -1000,9 +1003,22 @@ public void endElement(String uri, String localName, String qName) {
else if (qName.equals("bts:Ch")) {
int channelIndex = Integer.parseInt(value) - 1;
if (channelIndex >= 0 && channelIndex < channels.size()) {
// the same channel may be acquired multiple times
// if this is the first time the channel is acquired, set the indexes
// if this is the second (or more) time the channel is acquired,
// duplicate the channel so that each action has its own copy with
// the correct indexes
Channel ch = channels.get(channelIndex);
ch.timelineIndex = timelineIndex;
ch.actionIndex = actionIndex;
if (ch.timelineIndex == -1 && ch.actionIndex == -1) {
ch.timelineIndex = timelineIndex;
ch.actionIndex = actionIndex;
}
else {
Channel duplicate = new Channel(ch);
duplicate.timelineIndex = timelineIndex;
duplicate.actionIndex = actionIndex;
channels.add(duplicate);
}
}
}
}
Expand All @@ -1017,8 +1033,8 @@ class LightSource {
}

class Channel {
public int timelineIndex;
public int actionIndex;
public int timelineIndex = -1;
public int actionIndex = -1;
public int index;
public double xSize;
public double ySize;
Expand All @@ -1036,6 +1052,26 @@ class Channel {

public String fluor;

public Channel() {
}

public Channel(Channel ch) {
index = ch.index;
xSize = ch.xSize;
ySize = ch.ySize;
cameraNumber = ch.cameraNumber;
correctionFile = ch.correctionFile;
lightSourceRefs = ch.lightSourceRefs;
excitation = ch.excitation;
objectiveID = ch.objectiveID;
objective = ch.objective;
magnification = ch.magnification;
exposureTime = ch.exposureTime;
binning = ch.binning;
color = ch.color;
fluor = ch.fluor;
}

@Override
public String toString() {
return "timelineIndex=" + timelineIndex + ", actionIndex=" + actionIndex + ", index=" + index;
Expand Down

0 comments on commit 48c1baf

Please sign in to comment.