Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate objects when drawing #77

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
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
Loading