From 2fd3e1c8c8a4e1a886ea39211f4d5cef88939a22 Mon Sep 17 00:00:00 2001 From: Csaba Pinter Date: Sun, 12 Feb 2023 20:36:18 +0000 Subject: [PATCH] ENH: Apply treatment machine part file to RAS transform from JSON descriptor file Re #218 --- .../vtkSlicerRoomsEyeViewModuleLogic.cxx | 58 ++++++++++++++++++- .../Logic/vtkSlicerRoomsEyeViewModuleLogic.h | 5 +- .../VarianTrueBeamSTx/VarianTrueBeamSTx.json | 14 ++--- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx b/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx index ebbb85d7..a664f22c 100644 --- a/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx +++ b/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx @@ -539,6 +539,25 @@ void vtkSlicerRoomsEyeViewModuleLogic::SetupTreatmentMachineModels(vtkMRMLRoomsE partModel->CreateDefaultDisplayNodes(); partModel->GetDisplayNode()->SetColor((double)partColor[0] / 255.0, (double)partColor[1] / 255.0, (double)partColor[2] / 255.0); + // Apply file to RAS transform matrix + vtkNew fileToRASTransformMatrix; + if (this->GetFileToRASTransformMatrixForPartType(partType, fileToRASTransformMatrix)) + { + vtkNew fileToRASTransform; + fileToRASTransform->SetMatrix(fileToRASTransformMatrix); + vtkNew transformPolyDataFilter; + transformPolyDataFilter->SetInputConnection(partModel->GetPolyDataConnection()); + transformPolyDataFilter->SetTransform(fileToRASTransform); + transformPolyDataFilter->Update(); + vtkNew partPolyDataRAS; + partPolyDataRAS->DeepCopy(transformPolyDataFilter->GetOutput()); + partModel->SetAndObservePolyData(partPolyDataRAS); + } + else + { + vtkErrorMacro("SetupTreatmentMachineModels: Failed to set file to RAS matrix for treatment machine part " << partType); + } + // Setup transforms and collision detection if (partIdx == Collimator) { @@ -1495,9 +1514,44 @@ std::string vtkSlicerRoomsEyeViewModuleLogic::GetFilePathForPartType(std::string } //--------------------------------------------------------------------------- -bool vtkSlicerRoomsEyeViewModuleLogic::GetFileToPartTransformMatrixPartType(std::string partType, vtkMatrix4x4* fileToPartTransformMatrix) +bool vtkSlicerRoomsEyeViewModuleLogic::GetFileToRASTransformMatrixForPartType(std::string partType, vtkMatrix4x4* fileToPartTransformMatrix) { - //TODO: + if (!fileToPartTransformMatrix) + { + vtkErrorMacro("GetFileToRASTransformMatrixForPartType: Invalid treatment machine file to RAS matrix for part " << partType); + return false; + } + + fileToPartTransformMatrix->Identity(); + + rapidjson::Value& partObject = this->Internal->GetTreatmentMachinePart(partType); + if (partObject.IsNull()) + { + // The part may not have been included in the description + return false; + } + + rapidjson::Value& columnsArray = partObject["FileToRASTransformMatrix"]; + if (!columnsArray.IsArray() || columnsArray.Size() != 4) + { + vtkErrorMacro("GetFileToRASTransformMatrixForPartType: Invalid treatment machine file to RAS matrix for part " << partType); + return false; + } + + for (int i=0; iSetElement(i, j, columnsArray[i][j].GetDouble()); + } + } + return true; } diff --git a/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h b/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h index e9df246d..28d96d6f 100644 --- a/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h +++ b/RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h @@ -129,9 +129,10 @@ class VTK_SLICER_ROOMSEYEVIEW_LOGIC_EXPORT vtkSlicerRoomsEyeViewModuleLogic : std::string GetNameForPartType(std::string partType); /// Get relative file path for part type in the currently loaded treatment machine description std::string GetFilePathForPartType(std::string partType); - /// Get part name for part type in the currently loaded treatment machine description + /// Get transform matrix between loaded part file and RAS for part type in the currently loaded treatment machine description + /// \param fileToPartTransformMatrix Output file to RAS /// \return Success flag - bool GetFileToPartTransformMatrixPartType(std::string partType, vtkMatrix4x4* fileToPartTransformMatrix); + bool GetFileToRASTransformMatrixForPartType(std::string partType, vtkMatrix4x4* fileToPartTransformMatrix); /// Get part name for part type in the currently loaded treatment machine description vtkVector3d GetColorForPartType(std::string partType); /// Get part name for part type in the currently loaded treatment machine description diff --git a/RoomsEyeView/TreatmentMachineModels/VarianTrueBeamSTx/VarianTrueBeamSTx.json b/RoomsEyeView/TreatmentMachineModels/VarianTrueBeamSTx/VarianTrueBeamSTx.json index 59011947..4b64fb18 100644 --- a/RoomsEyeView/TreatmentMachineModels/VarianTrueBeamSTx/VarianTrueBeamSTx.json +++ b/RoomsEyeView/TreatmentMachineModels/VarianTrueBeamSTx/VarianTrueBeamSTx.json @@ -8,7 +8,7 @@ "Type": "Collimator", "Name": "Collimator", "FilePath": "Collimator.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [179, 179, 244], "State": "Active" }, @@ -16,7 +16,7 @@ "Type": "Gantry", "Name": "Gantry", "FilePath": "Gantry.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [244, 244, 244], "State": "Active" }, @@ -24,7 +24,7 @@ "Type": "ImagingPanelLeft", "Name": "Left imaging panel", "FilePath": "ImagingPanelLeft.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [244, 244, 244], "State": "Active" }, @@ -32,7 +32,7 @@ "Type": "ImagingPanelRight", "Name": "Right imaging panel", "FilePath": "ImagingPanelRight.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [244, 244, 244], "State": "Active" }, @@ -40,7 +40,7 @@ "Type": "Body", "Name": "Linac body", "FilePath": "LinacBody.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [230, 230, 230], "State": "Active" }, @@ -48,7 +48,7 @@ "Type": "PatientSupport", "Name": "Patient support", "FilePath": "PatientSupport.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [217, 217, 217], "State": "Active" }, @@ -56,7 +56,7 @@ "Type": "TableTop", "Name": "Table top", "FilePath": "TableTop.stl", - "FileToPartTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], + "FileToRASTransformMatrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ], "Color": [0, 0, 0], "State": "Active" }