diff --git a/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx b/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx index 1eeae29fd..772b1bd10 100644 --- a/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx +++ b/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx @@ -122,17 +122,23 @@ void vtkSlicerBeamsModuleLogic::OnMRMLSceneEndImport() scene->GetNodesByClass("vtkMRMLRTBeamNode", beamNodes); for (std::vector::iterator beamIt=beamNodes.begin(); beamIt!=beamNodes.end(); ++beamIt) { - vtkMRMLNode* node = (*beamIt); - + vtkMRMLRTBeamNode* beamNode = vtkMRMLRTBeamNode::SafeDownCast(*beamIt); + + // Re-observe poly data in beam model node + // Note: Without this, the beam polydata display is not updated when the beam geometry changes. The + // reason for this is possibly that the pipeline is set up with the file reader and on any modified + // event that pipeline is used instead of simply using the changed contents of the beam polydata. + beamNode->SetAndObserveMesh(beamNode->GetMesh()); + // Observe beam events vtkSmartPointer events = vtkSmartPointer::New(); events->InsertNextValue(vtkMRMLRTBeamNode::BeamGeometryModified); events->InsertNextValue(vtkMRMLRTBeamNode::BeamTransformModified); - vtkObserveMRMLNodeEventsMacro(node, events); + vtkObserveMRMLNodeEventsMacro(beamNode, events); // Make sure geometry and transforms are up-to-date - node->InvokeCustomModifiedEvent(vtkMRMLRTBeamNode::BeamGeometryModified); - node->InvokeCustomModifiedEvent(vtkMRMLRTBeamNode::BeamTransformModified); + beamNode->InvokeCustomModifiedEvent(vtkMRMLRTBeamNode::BeamGeometryModified); + beamNode->InvokeCustomModifiedEvent(vtkMRMLRTBeamNode::BeamTransformModified); } } diff --git a/Beams/MRML/vtkMRMLRTBeamNode.cxx b/Beams/MRML/vtkMRMLRTBeamNode.cxx index a95bca080..fe3a8c893 100644 --- a/Beams/MRML/vtkMRMLRTBeamNode.cxx +++ b/Beams/MRML/vtkMRMLRTBeamNode.cxx @@ -210,13 +210,19 @@ void vtkMRMLRTBeamNode::SetScene(vtkMRMLScene* scene) { Superclass::SetScene(scene); - if (scene) + if (!scene) + { + return; + } + + if (!this->GetPolyData()) { // Create beam model vtkSmartPointer beamModelPolyData = vtkSmartPointer::New(); - this->CreateBeamPolyData(beamModelPolyData); this->SetAndObservePolyData(beamModelPolyData); } + + this->CreateBeamPolyData(); } //---------------------------------------------------------------------------- @@ -455,12 +461,16 @@ void vtkMRMLRTBeamNode::UpdateGeometry() this->CreateDefaultDisplayNodes(); // Update beam poly data based on jaws and MLC - this->CreateBeamPolyData(this->GetPolyData()); + this->CreateBeamPolyData(); } //--------------------------------------------------------------------------- -void vtkMRMLRTBeamNode::CreateBeamPolyData(vtkPolyData* beamModelPolyData) +void vtkMRMLRTBeamNode::CreateBeamPolyData(vtkPolyData* beamModelPolyData/*=nullptr*/) { + if (!beamModelPolyData) + { + beamModelPolyData = this->GetPolyData(); + } if (!beamModelPolyData) { vtkErrorMacro("CreateBeamPolyData: Invalid beam node"); diff --git a/Beams/MRML/vtkMRMLRTBeamNode.h b/Beams/MRML/vtkMRMLRTBeamNode.h index 8e8fc9dad..c98b0da0a 100644 --- a/Beams/MRML/vtkMRMLRTBeamNode.h +++ b/Beams/MRML/vtkMRMLRTBeamNode.h @@ -181,7 +181,8 @@ class VTK_SLICER_BEAMS_MODULE_MRML_EXPORT vtkMRMLRTBeamNode : public vtkMRMLMode protected: /// Create beam model from beam parameters, supporting MLC leaves - void CreateBeamPolyData(vtkPolyData* beamModelPolyData); + /// \param beamModelPolyData Output polydata. If none given then the beam node's own polydata is used + void CreateBeamPolyData(vtkPolyData* beamModelPolyData=nullptr); protected: vtkMRMLRTBeamNode();