Skip to content

Commit

Permalink
BUG: Fix beam geometry modification in loaded scene
Browse files Browse the repository at this point in the history
The beam poly data in beam model node needs to be re-observed after import. 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.

Re #73
cpinter committed Jul 4, 2019
1 parent 7664806 commit 474905d
Showing 3 changed files with 27 additions and 10 deletions.
16 changes: 11 additions & 5 deletions Beams/Logic/vtkSlicerBeamsModuleLogic.cxx
Original file line number Diff line number Diff line change
@@ -122,17 +122,23 @@ void vtkSlicerBeamsModuleLogic::OnMRMLSceneEndImport()
scene->GetNodesByClass("vtkMRMLRTBeamNode", beamNodes);
for (std::vector<vtkMRMLNode*>::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<vtkIntArray> events = vtkSmartPointer<vtkIntArray>::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);
}
}

18 changes: 14 additions & 4 deletions Beams/MRML/vtkMRMLRTBeamNode.cxx
Original file line number Diff line number Diff line change
@@ -210,13 +210,19 @@ void vtkMRMLRTBeamNode::SetScene(vtkMRMLScene* scene)
{
Superclass::SetScene(scene);

if (scene)
if (!scene)
{
return;
}

if (!this->GetPolyData())
{
// Create beam model
vtkSmartPointer<vtkPolyData> beamModelPolyData = vtkSmartPointer<vtkPolyData>::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");
3 changes: 2 additions & 1 deletion Beams/MRML/vtkMRMLRTBeamNode.h
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 474905d

Please sign in to comment.