OHIF / react-vtkjs-viewport

VTK.js image viewport component in React
https://react-vtkjs-viewport.netlify.com/
MIT License
144 stars 82 forks source link

bringing in other widgets for segmentation / painting #158

Open shanebenlolo opened 2 years ago

shanebenlolo commented 2 years ago

I am trying to expand upon the functionality shown in this example https://react-vtkjs-viewport.netlify.app/painting to have more functionality and options like in this example https://kitware.github.io/vtk-js/examples/PaintWidget.html

I can import, and instantiate the wdigets like so:

    // brush types
    this.paintWidget = vtkPaintWidget.newInstance();
    this.paintWidget.setRadius(radius);
    this.rectangleWidget = vtkRectangleWidget.newInstance({
      resetAfterPointPlacement: true
    });

    widgets = [
      this.paintWidget,
      this.rectangleWidget
    ];

but when I replace paintWidget with rectangleWidget when adding a widget to the widgetManager like this:

    if (prevProps.painting !== this.props.painting) {
      if (this.props.painting) {
        this.viewWidget = this.widgetManager.addWidget(
          this.rectangleWidget,
          ViewTypes.SLICE
        );
        this.subs.paintStart.sub(
          this.viewWidget.onStartInteractionEvent(() => {
            this.paintFilter.startStroke();
            this.paintFilter.addPoint(
              this.rectangleWidget.getWidgetState().getTrueOrigin()
            );
            if (this.props.onPaintStart) {
              this.props.onPaintStart();
            }
          })
        );
        this.subs.paint.sub(
          this.viewWidget.onInteractionEvent(() => {
            if (this.viewWidget.getPainting()) {
              this.paintFilter.addPoint(
                this.rectangleWidget.getWidgetState().getTrueOrigin()
              );
              if (this.props.onPaint) {
                this.props.onPaint();
              }
            }
          })
        );
        this.subs.paintEnd.sub(
          this.viewWidget.onEndInteractionEvent(() => {
            const strokeBufferPromise = this.paintFilter.endStroke();

            if (this.props.onPaintEnd) {
              strokeBufferPromise.then(strokeBuffer => {
                this.props.onPaintEnd(strokeBuffer);
              });
            }
          })
        );

        this.widgetManager.grabFocus(this.rectangleWidget);
        this.widgetManager.enablePicking();

        this.genericRenderWindow.resize();
      } else if (this.viewWidget) {
        this.widgetManager.releaseFocus();
        this.widgetManager.removeWidget(this.rectangleWidget);
        this.widgetManager.disablePicking();

        this.subs.paintStart.unsubscribe();
        this.subs.paint.unsubscribe();
        this.subs.paintEnd.unsubscribe();
        this.viewWidget = null;

        this.genericRenderWindow.resize();
      }
    }

I receive the following error in OHIF: ViewerMain: Cannot read properties of null (reading 'isAttributeUsed'), this is the snippet of code throwing the error in index.js:

      if (program.isAttributeUsed('vertexDC')) {
        if (
          !cellBO
            .getVAO()
            .addAttributeArray(
              program,
              cellBO.getCABO(),
              'vertexDC',
              cellBO.getCABO().getVertexOffset(),
              cellBO.getCABO().getStride(),
              model.context.FLOAT,
              3,
              model.context.FALSE
            )
        ) {
          vtkErrorMacro('Error setting vertexDC in shader VAO.');
        }
      }

Does anyone know what I am doing wrong?