Bladeren bron

feat (1.67.0 -> 1.68.0): 实现文本标记工具定位功能,支持指定文本注解位置而非总是居中

- 在TextAnnotationTool.createDefaultAnnotation方法中添加可选position参数
- 在addLMark函数中使用指定位置[100,100]调用文本标记工具
- 更新TextAnnotationToolManager相关方法支持位置参数传递

改动文件:
- src/components/measures/TextAnnotationTool.ts
- src/pages/view/components/viewers/stack.image.viewer.tsx
- src/utils/textAnnotationToolManager.ts
dengdx 4 dagen geleden
bovenliggende
commit
c82f0a5a40

+ 12 - 0
CHANGELOG.md

@@ -2,6 +2,18 @@
 
 本项目的所有重要变更都将记录在此文件中.
 
+## [1.68.0] - 2026-01-13 18:00
+feat (1.67.0 -> 1.68.0): 实现文本标记工具定位功能,支持指定文本注解位置而非总是居中
+
+- 在TextAnnotationTool.createDefaultAnnotation方法中添加可选position参数
+- 在addLMark函数中使用指定位置[100,100]调用文本标记工具
+- 更新TextAnnotationToolManager相关方法支持位置参数传递
+
+改动文件:
+- src/components/measures/TextAnnotationTool.ts
+- src/pages/view/components/viewers/stack.image.viewer.tsx
+- src/utils/textAnnotationToolManager.ts
+
 ## [1.67.0] - 2026-01-13 10:15
 feat (1.66.2 -> 1.67.0): 实现文本标记工具功能,支持在图像上添加、编辑、旋转和缩放文本标注
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "zsis",
-  "version": "1.67.0",
+  "version": "1.68.0",
   "private": true,
   "description": "医学成像系统",
   "main": "main.js",

+ 21 - 6
src/components/measures/TextAnnotationTool.ts

@@ -119,11 +119,14 @@ export default class TextAnnotationTool extends AnnotationTool {
    * 创建一个预设的文本注解,带有默认文本框
    * @param element HTML元素
    * @param viewport Viewport实例
+   * @param text 文本内容
+   * @param position 可选的位置参数(canvas坐标),不提供时使用图像中心
    */
   static createDefaultAnnotation(
     element: HTMLDivElement,
     viewport: CoreTypes.IStackViewport | CoreTypes.IVolumeViewport,
-    text: string
+    text: string,
+    position?: Point2
   ): TextAnnotation {
     const enabledElement = getEnabledElement(element);
     if (!enabledElement) {
@@ -133,14 +136,26 @@ export default class TextAnnotationTool extends AnnotationTool {
     // 获取viewport的尺寸
     const canvas = viewport.canvas;
     const { width, height } = canvas;
-    const centerX = width / 2;
-    const centerY = height / 2;
 
-    // 创建默认文本框:中心位置,宽100,高40
+    // 创建默认文本框:宽100,高40
     const textBoxWidth = 100;
     const textBoxHeight = 40;
-    const textBoxLeft = centerX - textBoxWidth / 2;
-    const textBoxTop = centerY - textBoxHeight / 2;
+
+    // 如果提供了位置参数,使用该位置;否则使用图像中心
+    let textBoxLeft: number;
+    let textBoxTop: number;
+
+    if (position) {
+      // 使用提供的位置作为文本框中心
+      textBoxLeft = position[0] - textBoxWidth / 2;
+      textBoxTop = position[1] - textBoxHeight / 2;
+    } else {
+      // 使用图像中心
+      const centerX = width / 2;
+      const centerY = height / 2;
+      textBoxLeft = centerX - textBoxWidth / 2;
+      textBoxTop = centerY - textBoxHeight / 2;
+    }
 
     // 创建四个角点的canvas坐标
     const canvasPoints: CoreTypes.Point2[] = [

+ 1 - 1
src/pages/view/components/viewers/stack.image.viewer.tsx

@@ -373,7 +373,7 @@ function setupDefaultToolStates(toolGroup: cornerstoneTools.Types.IToolGroup) {
 }
 export function addLMark(currentViewportId: string): void {
   // 使用专门的文本标记工具管理器
-  TextAnnotationToolManager.activateTextAnnotationTool(currentViewportId, 'L');
+  TextAnnotationToolManager.activateTextAnnotationTool(currentViewportId, 'L',[100,100]);
 }
 export function addRLabel(currentViewportId: string): void {
   console.log('Adding R Mark viewport id : ', currentViewportId);

+ 11 - 4
src/utils/textAnnotationToolManager.ts

@@ -11,8 +11,11 @@ const { MouseBindings } = cornerstoneTools.Enums;
 export class TextAnnotationToolManager {
   /**
    * 激活文本标记工具
+   * @param viewportId 视口ID
+   * @param text 文本内容
+   * @param position 可选的位置参数(canvas坐标),不提供时使用图像中心
    */
-  static activateTextAnnotationTool(viewportId: string,text:string): boolean {
+  static activateTextAnnotationTool(viewportId: string, text: string, position?: cornerstone.Types.Point2): boolean {
     try {
       // 获取工具组
       const toolGroup = this.getToolGroup(viewportId);
@@ -44,7 +47,7 @@ export class TextAnnotationToolManager {
       }
 
       // 自动创建一个预设的注解
-      this.createDefaultAnnotation(viewportId, text);
+      this.createDefaultAnnotation(viewportId, text, position);
 
       console.log(`[TextAnnotationToolManager] TextAnnotationTool activated for viewport: ${viewportId}`);
       return true;
@@ -124,8 +127,11 @@ export class TextAnnotationToolManager {
 
   /**
    * 创建默认注解
+   * @param viewportId 视口ID
+   * @param text 文本内容
+   * @param position 可选的位置参数(canvas坐标),不提供时使用图像中心
    */
-  private static createDefaultAnnotation(viewportId: string,text:string): void {
+  private static createDefaultAnnotation(viewportId: string, text: string, position?: cornerstone.Types.Point2): void {
     try {
       const toolGroup = this.getToolGroup(viewportId);
       if (!toolGroup) return;
@@ -135,7 +141,8 @@ export class TextAnnotationToolManager {
       const defaultAnnotation = TextAnnotationTool.createDefaultAnnotation(
         viewport.element as HTMLDivElement,
         viewport as cornerstone.Types.IStackViewport,
-        text
+        text,
+        position
       );
 
       cornerstoneTools.annotation.state.addAnnotation(defaultAnnotation, viewport.element);