Skip to content

Commit

Permalink
Merge pull request #77 from brauliorivas/fix/remove-duplicates
Browse files Browse the repository at this point in the history
Remove duplicate objects when drawing
  • Loading branch information
kjvbrt authored Aug 12, 2024
2 parents 4ba0b9b + 24cfcbe commit 57d2787
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
37 changes: 32 additions & 5 deletions js/filters/pre-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@ export function preFilterAssociation(

const association = currentObjects.associations[associationName];

const fromCollection = association.map((association) => association.from);
const added = new Set();
const fromCollection = [];
const toCollection = [];

const toCollection = association.map((association) => association.to);
association.forEach((relation) => {
const from = relation.from;
const fromId = `${from.index}-${from.collectionId}`;

viewObjects.datatypes[fromCollectionName].collection = fromCollection;
if (!added.has(fromId)) {
added.add(fromId);
fromCollection.push(from);
}

viewObjects.datatypes[toCollectionName].collection = toCollection;
const to = relation.to;
const toId = `${to.index}-${to.collectionId}`;

if (!added.has(toId)) {
added.add(toId);
toCollection.push(to);
}
});

viewObjects.datatypes[fromCollectionName].collection = fromCollection;
viewObjects.datatypes[toCollectionName].collection = toCollection;
viewObjects.associations[associationName] = association;
}

Expand Down Expand Up @@ -58,7 +74,18 @@ export function preFilterOneWay(
currentObjects.datatypes[fromCollectionName].oneToOne[relationName];

const fromCollection = relations.map((relation) => relation.from);
const toCollection = relations.map((relation) => relation.to);

const added = new Set();
const toCollection = [];
relations.forEach((relation) => {
const to = relation.to;
const toId = `${to.index}-${to.collectionId}`;

if (!added.has(toId)) {
added.add(toId);
toCollection.push(to);
}
});

viewObjects.datatypes[fromCollectionName].oneToOne[relationName] = relations;
viewObjects.datatypes[fromCollectionName].collection = fromCollection;
Expand Down
35 changes: 30 additions & 5 deletions js/views/templates/recoclustertrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,38 +135,63 @@ export function preFilterRecoClusterTrackVertex(currentObjects, viewObjects) {

const fromCollection = fromDatatype.collection;

const added = new Set();

const recoParticles = [];
const clusters = [];
const tracks = [];
const vertexCollection = [];

fromCollection.forEach((particle) => {
const id = `${particle.index}-${particle.collectionId}`;

const clusterRelations = particle.oneToManyRelations["clusters"];
const trackRelations = particle.oneToManyRelations["tracks"];
const vertexRelation = particle.oneToOneRelations["startVertex"];

const total = clusterRelations.length + trackRelations.length;
const total =
clusterRelations.length +
trackRelations.length +
(vertexRelation !== undefined ? 1 : 0);

if (total === 0) {
return;
}

clusterRelations.forEach((clusterRelation) => {
const cluster = clusterRelation.to;
clusters.push(cluster);
const clusterId = `${cluster.index}-${cluster.collectionId}`;

if (!added.has(clusterId)) {
added.add(clusterId);
clusters.push(cluster);
}
});

trackRelations.forEach((trackRelation) => {
const track = trackRelation.to;
tracks.push(track);
const trackId = `${track.index}-${track.collectionId}`;

if (!added.has(trackId)) {
added.add(trackId);
tracks.push(track);
}
});

if (vertexRelation !== undefined) {
const vertex = vertexRelation.to;
vertexCollection.push(vertex);
const vertexId = `${vertex.index}-${vertex.collectionId}`;

if (!added.has(vertexId)) {
added.add(vertexId);
vertexCollection.push(vertex);
}
}

recoParticles.push(particle);
if (!added.has(id)) {
added.add(id);
recoParticles.push(particle);
}
});

viewObjects.datatypes["edm4hep::ReconstructedParticle"].collection =
Expand Down

0 comments on commit 57d2787

Please sign in to comment.