Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/painters/data-model-painter.ts is written in an unsupported language. File is not indexed.

0001 /**
0002  * This class is responsible in rendering Event or Frame data.
0003  * It first takes event components and manipulates three.js Scene
0004  * Then responsible for correct rendering at a given time
0005  */
0006 
0007 import { Entry } from "../model/entry";
0008 import { Object3D, Group } from "three";
0009 import {ComponentPainter, ComponentPainterConstructor} from "./component-painter";
0010 import {BoxTrackerHitComponent} from "../model/box-tracker-hit.component";
0011 import {BoxTrackerHitPainter} from "./box-tracker-hit.painter";
0012 import {BoxTrackerHitSimplePainter} from "./box-tracker-hit-simple.painter";
0013 
0014 
0015 export class DataModelPainter {
0016   private threeParentNode: Object3D | null = null;
0017   private entry: Entry | null = null;
0018   private painters: ComponentPainter[] = [];
0019   // Create the registry
0020   componentPainterRegistry: { [type: string]: ComponentPainterConstructor } = {};
0021 
0022   public constructor() {
0023     // Register builtin painters
0024     //this.registerPainter(BoxTrackerHitComponent.type, BoxTrackerHitPainter);
0025     this.registerPainter(BoxTrackerHitComponent.type, BoxTrackerHitSimplePainter);
0026 
0027   }
0028 
0029   public setThreeSceneParent(parentNode: Object3D) {
0030     this.threeParentNode = parentNode;
0031   }
0032 
0033   protected cleanupCurrentEntry() {
0034     for (let painter of this.painters) {
0035       painter.dispose();
0036     }
0037     this.painters = [];
0038   }
0039 
0040   public setEntry(entry: Entry): void {
0041     this.cleanupCurrentEntry();
0042     this.entry = entry;
0043 
0044     if (!this.threeParentNode) {
0045       throw new Error('Three.js parent node is not set.');
0046     }
0047 
0048     for (const component of entry.components) {
0049       const PainterClass = this.componentPainterRegistry[component.type];
0050       if (PainterClass) {
0051         let componentGroup = new Group();
0052         componentGroup.name = component.name;
0053         componentGroup.userData['component'] = component;
0054         this.threeParentNode.add(componentGroup);
0055         const painter = new PainterClass(componentGroup, component);
0056 
0057         this.painters.push(painter);
0058       } else {
0059         console.warn(`No ComponentPainter registered for component type: ${component.type}`);
0060       }
0061     }
0062   }
0063 
0064   /**
0065    * Registers a custom painter class provided by the user.
0066    *
0067    * @param componentType - The type of the component for which the painter should be used.
0068    * @param painterClass - The user's custom ComponentPainter subclass.
0069    */
0070   public registerPainter(componentType: string, painterClass: ComponentPainterConstructor): void {
0071     if (!componentType || !painterClass) {
0072       throw new Error('Both componentType and painterClass are required to register a custom painter.');
0073     }
0074     this.componentPainterRegistry[componentType] = painterClass;
0075   }
0076 
0077   /** paints scene at the current time. null - no-time mode (draws everything) */
0078   public paint(time: number | null): void {
0079     for (let painter of this.painters) {
0080       painter.paint(time);
0081     }
0082   }
0083 }