Skip to content
Browse files

BUG: Move light box renderer manager proxy to abstract displayable ma…

…nager

Suggested by Steve Pieper
Contributed by Jim Miller

Moved the LightBoxRendererManagerProxy up to the superclass of the
DisplayableManager hierarchy so that all (2D & 3D) displayable managers
can interact with a lightbox.

Note that light boxes are only currently supported on 2D viewers, so the
proxy is only configured in qMRMLSliceView. CTK will need to be changed to
put the LightBoxManager into ctkVTKAbstractView to make it accessible to
both ctkVTKSliceView and ctkVTKRenderView. Then qMRMLThreeDView could also
create and initialize a LightBoxManagerProxy and set it on its DisplayableManagers.
Here, we would also want to move qMRMLSliceViewPrivate::vtkInternalLightBoxRendererManagerProxy
class to a place where it could be used by both types of VTK widgets.

The proxy can now be set on the DisplayableManagerGroup which
broadcasts the proxy to all the DisplayableManagers in that group.

See http://www.na-mic.org/Bug/view.php?id=2732

Fixes #2732

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21431 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
1 parent 546a2ad commit 5ca85f36d14d3d7d8bfe9b61821c16560541e70b @jcfr committed Nov 16, 2012
View
33 Libs/MRML/DisplayableManager/vtkMRMLAbstractDisplayableManager.cxx
@@ -21,6 +21,7 @@
// MRMLDisplayableManager includes
#include "vtkMRMLAbstractDisplayableManager.h"
#include "vtkMRMLDisplayableManagerGroup.h"
+#include <vtkMRMLLightBoxRendererManagerProxy.h>
// MRMLLogic includes
#include <vtkMRMLApplicationLogic.h>
@@ -37,6 +38,7 @@
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
+#include <vtkWeakPointer.h>
// STD includes
#include <cassert>
@@ -129,6 +131,8 @@ class vtkMRMLAbstractDisplayableManager::vtkInternal
vtkInteractorObserver* InteractorStyle;
vtkSmartPointer<vtkCallbackCommand> InteractorStyleCallBackCommand;
std::vector<std::pair<int,float> > InteractorStyleObservableEvents;
+ vtkWeakPointer<vtkMRMLLightBoxRendererManagerProxy> LightBoxRendererManagerProxy;
+
};
//----------------------------------------------------------------------------
@@ -142,6 +146,7 @@ vtkMRMLAbstractDisplayableManager::vtkInternal::vtkInternal(
this->WidgetsObserverManager = vtkObserverManager::New();
this->UpdateFromMRMLRequested = false;
this->Renderer = 0;
+ this->LightBoxRendererManagerProxy = 0;
this->MRMLDisplayableNode = 0;
this->MRMLDisplayableNodeObservableEvents = vtkSmartPointer<vtkIntArray>::New();
this->DisplayableManagerGroup = 0;
@@ -187,7 +192,7 @@ vtkMRMLAbstractDisplayableManager::vtkInternal::~vtkInternal()
this->SetAndObserveInteractor(0);
this->SetAndObserveInteractorStyle(0);
this->SetAndObserveMRMLInteractionNode(0);
-
+ this->LightBoxRendererManagerProxy = 0;
this->WidgetsObserverManager->Delete();
}
@@ -938,3 +943,29 @@ void vtkMRMLAbstractDisplayableManager::InteractorAbortFlagOff()
{
this->Internal->InteractorCallBackCommand->AbortFlagOff();
}
+
+//---------------------------------------------------------------------------
+void vtkMRMLAbstractDisplayableManager::SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy* mgr)
+{
+ this->Internal->LightBoxRendererManagerProxy = mgr;
+}
+
+//---------------------------------------------------------------------------
+vtkMRMLLightBoxRendererManagerProxy* vtkMRMLAbstractDisplayableManager::GetLightBoxRendererManagerProxy()
+{
+ return this->Internal->LightBoxRendererManagerProxy;
+}
+
+//---------------------------------------------------------------------------
+vtkRenderer* vtkMRMLAbstractDisplayableManager::GetRenderer(int idx)
+{
+ if (this->Internal->LightBoxRendererManagerProxy)
+ {
+ return this->Internal->LightBoxRendererManagerProxy->GetRenderer(idx);
+ }
+ else
+ {
+ return this->GetRenderer();
+ }
+}
+
View
21 Libs/MRML/DisplayableManager/vtkMRMLAbstractDisplayableManager.h
@@ -31,6 +31,7 @@ class vtkMRMLSelectionNode;
class vtkMRMLDisplayableManagerGroup;
class vtkMRMLNode;
class vtkMRMLScene;
+class vtkMRMLLightBoxRendererManagerProxy;
class vtkRenderer;
class vtkRenderWindowInteractor;
@@ -54,9 +55,27 @@ class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLAbstractDisplayableManager
/// \sa CreateIfPossible() Create()
bool IsCreated();
- /// Get Renderer
+ /// Set the LightBoxRendererManager proxy. This proxy provides a
+ /// method GetRenderer(int) that returns the renderer for the ith
+ /// lightbox pane. The DisplayableManagers use this method to map
+ /// coordinates to the proper lightbox pane, e.g. in placing
+ /// crosshairs or annotations in the proper renderer.
+ virtual void SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy *);
+
+ /// Get the LightBoxRendererManagerProxy if one has been provided
+ /// \sa SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy *)
+ virtual vtkMRMLLightBoxRendererManagerProxy* GetLightBoxRendererManagerProxy();
+
+ /// Get the default renderer for this displayable manager.
vtkRenderer* GetRenderer();
+ /// Get the renderer for the ith lightbox pane. This method uses the
+ /// LightBoxRendererManagerProxy if one has been configured for the
+ /// DisplayableManager. If no LightBoxRendererManagerProxy has been
+ /// set, this method returns the default renderer by deferring to
+ /// GetRenderer(),
+ vtkRenderer* GetRenderer(int idx);
+
/// Convenient method to get the WindowInteractor associated with the Renderer
vtkRenderWindowInteractor* GetInteractor();
View
14 Libs/MRML/DisplayableManager/vtkMRMLCrosshairDisplayableManager.cxx
@@ -122,7 +122,6 @@ class vtkMRMLCrosshairDisplayableManager::vtkInternal
vtkSmartPointer<vtkActor2D> HighlightActor;
vtkSmartPointer<vtkMRMLCrosshairNode> CrosshairNodeCache;
vtkWeakPointer<vtkRenderer> LightBoxRenderer;
- vtkWeakPointer<vtkMRMLLightBoxRendererManagerProxy> LightBoxRendererManagerProxy;
};
@@ -141,7 +140,6 @@ ::vtkInternal(vtkMRMLCrosshairDisplayableManager * external)
this->Actor = 0;
this->HighlightActor = 0;
this->LightBoxRenderer = 0;
- this->LightBoxRendererManagerProxy = 0;
this->CrosshairNodeCache = vtkSmartPointer<vtkMRMLCrosshairNode>::New();
}
@@ -151,7 +149,6 @@ vtkMRMLCrosshairDisplayableManager::vtkInternal::~vtkInternal()
this->SetSliceCompositeNode(0);
this->SetCrosshairNode(0);
this->LightBoxRenderer = 0;
- this->LightBoxRendererManagerProxy = 0;
this->CrosshairNodeCache = 0;
// everything should be empty
assert(this->SliceCompositeNode == 0);
@@ -609,11 +606,11 @@ void vtkMRMLCrosshairDisplayableManager::OnMRMLNodeModified(vtkMRMLNode* node)
this->Internal->HighlightActor->SetPosition(xyz[0], xyz[1]);
// put the actor in the right lightbox
- if (this->Internal->LightBoxRendererManagerProxy)
+ if (this->GetLightBoxRendererManagerProxy())
{
int id = (int) (xyz[2] + 0.5); // round to find the lightbox
vtkRenderer *renderer
- = this->Internal->LightBoxRendererManagerProxy->GetRenderer(id);
+ = this->GetLightBoxRendererManagerProxy()->GetRenderer(id);
if (renderer != this->Internal->LightBoxRenderer)
{
if (this->Internal->LightBoxRenderer)
@@ -688,7 +685,7 @@ void vtkMRMLCrosshairDisplayableManager::OnInteractorStyleEvent(int eventid)
{
double xyz[3], ras[3];
vtkRenderer *renderer
- = this->Internal->LightBoxRendererManagerProxy->GetRenderer(0);
+ = this->GetLightBoxRendererManagerProxy()->GetRenderer(0);
xyz[0] = renderer->GetSize()[0] / 2.0;
xyz[1] = renderer->GetSize()[1] / 2.0;
xyz[2] = 0;
@@ -886,10 +883,5 @@ void vtkMRMLCrosshairDisplayableManager::AdditionalInitializeStep()
}
-//---------------------------------------------------------------------------
-void vtkMRMLCrosshairDisplayableManager::SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy* mgr)
-{
- this->Internal->LightBoxRendererManagerProxy = mgr;
-}
View
5 Libs/MRML/DisplayableManager/vtkMRMLCrosshairDisplayableManager.h
@@ -25,8 +25,6 @@
#include "vtkMRMLAbstractSliceViewDisplayableManager.h"
#include "vtkMRMLDisplayableManagerWin32Header.h"
-class vtkMRMLLightBoxRendererManagerProxy;
-
/// \brief Displayable manager for the crosshair on slice (2D) views
///
/// Responsible for any display of the crosshair on Slice views.
@@ -39,9 +37,6 @@ class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLCrosshairDisplayableManager :
vtkMRMLAbstractSliceViewDisplayableManager);
void PrintSelf(ostream& os, vtkIndent indent);
- /// Set the LightBoxRendererManager proxy
- virtual void SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy *);
-
protected:
vtkMRMLCrosshairDisplayableManager();
virtual ~vtkMRMLCrosshairDisplayableManager();
View
30 Libs/MRML/DisplayableManager/vtkMRMLDisplayableManagerGroup.cxx
@@ -22,6 +22,7 @@
#include "vtkMRMLAbstractDisplayableManager.h"
#include "vtkMRMLDisplayableManagerGroup.h"
#include "vtkMRMLDisplayableManagerFactory.h"
+#include <vtkMRMLLightBoxRendererManagerProxy.h>
#ifdef MRMLDisplayableManager_USE_PYTHON
#include "vtkMRMLScriptedDisplayableManager.h"
@@ -37,6 +38,7 @@
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
+#include <vtkWeakPointer.h>
// STD includes
#include <algorithm>
@@ -70,6 +72,7 @@ class vtkMRMLDisplayableManagerGroup::vtkInternal
vtkMRMLDisplayableManagerFactory* DisplayableManagerFactory;
vtkMRMLNode* MRMLDisplayableNode;
vtkRenderer* Renderer;
+ vtkWeakPointer<vtkMRMLLightBoxRendererManagerProxy> LightBoxRendererManagerProxy;
};
//----------------------------------------------------------------------------
@@ -82,6 +85,7 @@ vtkMRMLDisplayableManagerGroup::vtkInternal::vtkInternal()
this->Renderer = 0;
this->CallBackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
this->DisplayableManagerFactory = 0;
+ this->LightBoxRendererManagerProxy = 0;
}
//----------------------------------------------------------------------------
@@ -111,6 +115,11 @@ vtkMRMLDisplayableManagerGroup::~vtkMRMLDisplayableManagerGroup()
this->Internal->Renderer->UnRegister(this);
}
+ if (this->Internal->LightBoxRendererManagerProxy)
+ {
+ this->Internal->LightBoxRendererManagerProxy = 0;
+ }
+
delete this->Internal;
}
@@ -262,6 +271,10 @@ void vtkMRMLDisplayableManagerGroup::AddDisplayableManager(
this->Internal->DisplayableManagerFactory->GetMRMLApplicationLogic());
}
displayableManager->SetRenderer(this->Internal->Renderer);
+
+ // pass the lightbox manager proxy to the new displayable manager
+ displayableManager->SetLightBoxRendererManagerProxy(this->Internal->LightBoxRendererManagerProxy);
+
displayableManager->SetAndObserveMRMLDisplayableNode(this->GetMRMLDisplayableNode());
displayableManager->Register(this);
@@ -458,3 +471,20 @@ void vtkMRMLDisplayableManagerGroup::onDisplayableManagerFactoryUnRegisteredEven
vtkDebugMacro(<< "group:" << this << ", onDisplayableManagerFactoryUnRegisteredEvent:"
<< displayableManagerName)
}
+
+//---------------------------------------------------------------------------
+void vtkMRMLDisplayableManagerGroup::SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy* mgr)
+{
+ this->Internal->LightBoxRendererManagerProxy = mgr;
+
+ for(size_t i=0; i < this->Internal->DisplayableManagers.size(); ++i)
+ {
+ this->Internal->DisplayableManagers[i]->SetLightBoxRendererManagerProxy(this->Internal->LightBoxRendererManagerProxy);
+ }
+}
+
+//---------------------------------------------------------------------------
+vtkMRMLLightBoxRendererManagerProxy* vtkMRMLDisplayableManagerGroup::GetLightBoxRendererManagerProxy()
+{
+ return this->Internal->LightBoxRendererManagerProxy;
+}
View
15 Libs/MRML/DisplayableManager/vtkMRMLDisplayableManagerGroup.h
@@ -28,6 +28,7 @@
class vtkMRMLDisplayableManagerFactory;
class vtkMRMLAbstractDisplayableManager;
+class vtkMRMLLightBoxRendererManagerProxy;
class vtkMRMLNode;
class vtkRenderer;
class vtkRenderWindowInteractor;
@@ -100,6 +101,20 @@ class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLDisplayableManagerGroup : public
static vtkMRMLAbstractDisplayableManager* InstantiateDisplayableManager(
const char* displayableManagerName);
+
+ /// Set the LightBoxRendererManagerProxy on the
+ /// DisplayableManagerGroup. This caches the proxy and broadcasts
+ /// the proxy to all DisplayableManagers in the group. This proxy
+ /// provides a method GetRenderer(int) that returns the renderer for
+ /// the ith lightbox pane. The DisplayableManagers use this method
+ /// to map coordinates to the proper lightbox pane, e.g. in placing
+ /// crosshairs or annotations in the proper renderer.
+ virtual void SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy *);
+
+ /// Get the LightBoxRendererManagerProxy if one has been provided.
+ /// \sa SetLightBoxRendererManagerProxy(vtkMRMLLightBoxRendererManagerProxy *)
+ virtual vtkMRMLLightBoxRendererManagerProxy* GetLightBoxRendererManagerProxy();
+
protected:
vtkMRMLDisplayableManagerGroup();
View
12 Libs/MRML/Widgets/qMRMLSliceView.cxx
@@ -176,15 +176,9 @@ void qMRMLSliceViewPrivate::initDisplayableManagers()
q->qvtkConnect(this->DisplayableManagerGroup, vtkCommand::UpdateEvent,
q, SLOT(scheduleRender()));
- // pass the lightbox manager proxy on the CrosshairDisplayableManager
- vtkMRMLCrosshairDisplayableManager *cmgr =
- vtkMRMLCrosshairDisplayableManager::SafeDownCast(
- this->DisplayableManagerGroup->GetDisplayableManagerByClassName("vtkMRMLCrosshairDisplayableManager"));
- if (cmgr)
- {
- cmgr->SetLightBoxRendererManagerProxy(
- this->LightBoxRendererManagerProxy);
- }
+ // pass the lightbox manager proxy onto the display managers
+ this->DisplayableManagerGroup->SetLightBoxRendererManagerProxy(this->LightBoxRendererManagerProxy);
+
}
//---------------------------------------------------------------------------

0 comments on commit 5ca85f3

Please sign in to comment.
Something went wrong with that request. Please try again.