Closed mah-developer closed 2 months ago
Hello all,
when you encountered this error it's because you didn't add your tools to cornerstoneTools.
Before adding tool to this property and set tool activate from this property private toolGroup!: ToolGroup | undefined;
like bellow:
public addBrushTool() {
this.toolGroup!.addTool(BrushTool.toolName, { toolLayer: true });
}
public setBrushToolActivate() {
this.toolGroup!.setToolActive(BrushTool.toolName, {
bindings: [{ mouseButton: ToolsEnums.MouseBindings.Primary }]
});
}
You only need invole addTool()
method from @cornerstonejs/tools and pass your tool to it:
...
import { BrushTool, AnnotationTool, addTool, destroy, Enums as ToolsEnums, init as initTools, ToolGroupManager, segmentation} from '@cornerstonejs/tools';
public addBrushTool() {
// Register tools
addTool(BrushTool);
this.toolGroup!.addTool(BrushTool.toolName, { toolLayer: true });
}
....
You can do that in addBrushTool()
method.
Prerequisites
cornerstoneTools
Tools not working in Angular 8
andcornerstoneTools.init() returns undefined
.Steps to Reproduce the Issue
Add the following buttons to the component's markup:
Clicking the
Add Brush Tool
button results in the following console error:Clicking the
Set Brush Tool Activate
button results in the following console error:Investigation
The errors indicate that the Brush tool is not being properly registered or added to the tool group. Here's a detailed analysis:
Error During Tool Addition:
The error suggests that
'Brush'
is not registered with the library. In theaddTool
method withinToolGroup.ts
, the following warning is triggered:This implies that the Brush tool needs to be explicitly registered before it can be added to the tool group.
Error During Tool Activation:
The error message:
indicates that even after attempting to add the Brush tool, it is not present in
this._toolInstances
within theToolGroup
, preventing it from being activated.Code Analysis:
In
cornerstone.service.ts
, the methods for adding and activating the Brush tool are defined as:However, the
addTool
method seems to expect the tool name to be registered beforehand usingcornerstoneTools.addTool
.Potential Issues Identified:
cornerstoneTools
before attempting to add it to the tool group.ToolGroup
is imported from a deep internal path, which might not be the intended usage and could lead to issues.cornerstoneTools
andcornerstone-core
being used.Questions
Tool Registration: Am I missing a step in registering the
BrushTool
withcornerstoneTools
before adding it to the tool group?Imports: I am importing the
ToolGroup
from the following path:Is this the correct import path, or should I be using a different one?
Version Compatibility: Could this issue be related to the specific versions of
cornerstoneTools
andcornerstone-core
that I am using? If so, what would be the recommended version combination for Angular 18?Additional Details
Error Trace in
ToolGroup.ts
:Activation Method in
ToolGroup.ts
:These snippets show that without proper registration using
cornerstoneTools.addTool
, the tool cannot be added or activated within the tool group.Environment Details
package.json
snippet above.Any guidance or suggestions to resolve these issues would be greatly appreciated. Thank you!