Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add / Remove Nodes in FreehandRoi Tool

See original GitHub issue


  • Latest
  • Are you reporting to the correct repository?
  • No related issues, one of them got me no answers.


I would like to know, if there is a possibility to add or remove nodes after the tool has been closed. I am thinking of it as getting the coords from the mouse, and on click, check the tool state and if there is an existing node, remove it (causes error) and re-render the state, and if there is no node, then add it and as well re-render the state.

Expected behavior:

When adding or removing nodes from a rendered tool, be able to add or remove this information from the tool state’s object and re-render the tool state to update the view with/without the selected nodes.

Actual behavior:

After removing or adding a node from the tool state’s object, changing the lines coordinates and re-rendering, after a click or movement the tool crashes stating Undefined is not an object.

As usual, thanks in advance.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

HoAnhVancommented, Dec 10, 2020
export const undoFreehandPoint = (toolName, enableElement) => {
  if (!toolName || !enableElement) return;
  try {
    const tool = cornerstoneTools.getToolForElement(enableElement, toolName);
    const activeDrawing = (tool || {})._activeDrawingToolReference;
    if (
      activeDrawing &&
      activeDrawing.handles &&
      (activeDrawing.handles.points || []).length > 1
    ) {
      const configuration = tool._configuration;

      if (configuration.currentHandle > 1) {
        const len = activeDrawing.handles.points.length;
        activeDrawing.handles.points.length = len - 1;
        activeDrawing.handles.points[len - 2].lines = [];
        configuration.currentHandle = configuration.currentHandle - 1;
  } catch (error) {
pzehlecommented, Mar 31, 2020

@dannyrb thanks for your response. What I am currently doing as an example on my project is:

Every time I mark a point with the Freehand tool, I am saving the state of the tool in React’s state. At any moment, I can press ‘cmd + z’ and the last node will get deleted from the state, with the following code:

undoPoint = () => {
	var markings = cornerstoneTools.getToolState(this.element, 'FreehandRoi');
	var data =[0];
	if(data.handles.points.length === 1) {
		return false;
	} else {
		let latestPoint = data.handles.points.length - 1;
		data.handles.points[latestPoint].lines = [];
		cornerstoneTools.clearToolState(this.element, 'FreehandRoi');
		cornerstoneTools.addToolState(this.element, 'FreehandRoi', data);

I am removing the last available node’s lines array as the last node should not have lines, AFAIK. This all works correctly, but after continuing with the marking, the next point I mark makes my application crash and output the following error:

cornerstoneTools.js:32070 Uncaught TypeError: Cannot read property 'lines' of undefined
    at FreehandRoiTool._addPoint (cornerstoneTools.js:32070)
    at FreehandRoiTool._drawingMouseDownCallback (cornerstoneTools.js:31756)
    at triggerEvent (cornerstoneTools.js:48197)
    at HTMLDivElement.mouseDown (cornerstoneTools.js:8356)
_addPoint @ cornerstoneTools.js:32070
_drawingMouseDownCallback @ cornerstoneTools.js:31756
triggerEvent @ cornerstoneTools.js:48197
mouseDown @ cornerstoneTools.js:8356
cornerstoneTools.js:32070 Uncaught TypeError: Cannot read property 'lines' of undefined
    at FreehandRoiTool._addPoint (cornerstoneTools.js:32070)
    at FreehandRoiTool._addPointPencilMode (cornerstoneTools.js:32106)
    at FreehandRoiTool._drawingDrag (cornerstoneTools.js:31685)
    at FreehandRoiTool._drawingMouseDragCallback (cornerstoneTools.js:31656)
    at triggerEvent (cornerstoneTools.js:48197)
    at HTMLDocument.onMouseMove (cornerstoneTools.js:8398)

When comparing two objects, the first being an object being generated as I mark lesions, and the second object being the object output after the undo function, they seem exactly the same. I don’t really know if internally there is a points or lines counter on the cornerstoneTools’ object or something that is making this error appear after removing a node from the array.

I am putting here a small vide as an example of the things I described above.

I hope this can make my issue clearer. Thanks again.


Read more comments on GitHub >

github_iconTop Results From Across the Web

I want to share my overhauled freehand tool, seeking advice ...
Hey all, I have built upon the unfinished cornerstoneTools freehand tool, adding the following functionality: Statistics: -- Added general area calculation ...
Read more >
SUMA documentation - AFNI
SUMA (SUrface MApping). SUMA is a program that adds cortical surface based functional imaging analysis to the AFNI suite of programs http://afni.nimh.
Read more >
FreehandRoi Tool - cornerstone-tools
CornerstoneTools.js is a light-weight solution for building Tools on top of Cornerstone.js. It's only dependencies are libraries within the Cornerstone family.
Read more >
Corel Draw Tips & Tricks Remove Nodes and how to - YouTube
Corel Draw Tips & Tricks Remove Nodes and how to. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >
Visage Imaging - Online Help
Delete All Measurements/Annotations . ... Tools for automatic removal of structures . ... Select a server, network node, or drive to add this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found