Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSlicerMarkupsWidgetRepresentation3D.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Copyright (c) ProxSim ltd., Kwun Tong, Hong Kong. All Rights Reserved.
4 
5  See COPYRIGHT.txt
6  or http://www.slicer.org/copyright/copyright.txt for details.
7 
8  Unless required by applicable law or agreed to in writing, software
9  distributed under the License is distributed on an "AS IS" BASIS,
10  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  See the License for the specific language governing permissions and
12  limitations under the License.
13 
14  This file was originally developed by Davide Punzo, punzodavide@hotmail.it,
15  and development was supported by ProxSim ltd.
16 
17 =========================================================================*/
18 
27 #ifndef vtkSlicerMarkupsWidgetRepresentation3D_h
28 #define vtkSlicerMarkupsWidgetRepresentation3D_h
29 
30 #include "vtkSlicerMarkupsModuleVTKWidgetsExport.h"
32 
33 #include <map>
34 
35 class vtkActor;
36 class vtkActor2D;
37 class vtkCellPicker;
39 class vtkGlyph3DMapper;
40 class vtkLabelPlacementMapper;
41 class vtkPolyDataMapper;
42 class vtkProperty;
43 
45 
46 class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidgetRepresentation3D : public vtkSlicerMarkupsWidgetRepresentation
47 {
48 public:
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
53  void SetRenderer(vtkRenderer *ren) override;
54 
58  void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void *callData = nullptr) override;
59 
61  void GetActors(vtkPropCollection *) override;
62  void ReleaseGraphicsResources(vtkWindow *) override;
63  int RenderOverlay(vtkViewport *viewport) override;
64  int RenderOpaqueGeometry(vtkViewport *viewport) override;
65  int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override;
66  vtkTypeBool HasTranslucentPolygonalGeometry() override;
67 
69  double *GetBounds() override;
70 
71  void CanInteract(vtkMRMLInteractionEventData* interactionEventData,
72  int &foundComponentType, int &foundComponentIndex, double &closestDistance2) override;
73 
75  virtual void CanInteractWithHandles(vtkMRMLInteractionEventData* interactionEventData,
76  int& foundComponentType, int& foundComponentIndex, double& closestDistance2);
77 
80  void CanInteractWithLine(vtkMRMLInteractionEventData* interactionEventData,
81  int &foundComponentType, int &foundComponentIndex, double &closestDistance2);
82 
83  bool AccuratePick(int x, int y, double pickPoint[3], double pickNormal[3]=nullptr);
84 
88  bool GetNthControlPointViewVisibility(int n);
89 
94  vtkSetMacro(OccludedRelativeOffset, double);
95  vtkGetMacro(OccludedRelativeOffset, double);
96 
97 protected:
100 
101  double GetViewScaleFactorAtPosition(double positionWorld[3], vtkMRMLInteractionEventData* interactionEventData = nullptr);
102 
103  void UpdateViewScaleFactor() override;
104 
105  void UpdateControlPointSize() override;
106 
107  void UpdateInteractionPipeline() override;
108 
109  class ControlPointsPipeline3D : public ControlPointsPipeline
110  {
111  public:
113  ~ControlPointsPipeline3D() override;
114 
116  vtkSmartPointer<vtkDoubleArray> GlyphOrientationArray;
117 
118  vtkSmartPointer<vtkGlyph3DMapper> GlyphMapper;
119 
120  // Properties used to control the appearance of selected objects and
121  // the manipulator in general.
122  vtkSmartPointer<vtkProperty> Property;
123  vtkSmartPointer<vtkProperty> OccludedProperty;
124  vtkSmartPointer<vtkTextProperty> OccludedTextProperty;
125 
126  vtkSmartPointer<vtkPolyData> VisiblePointsPolyData;
127 
128  vtkSmartPointer<vtkFastSelectVisiblePoints> SelectVisiblePoints;
129 
130  vtkSmartPointer<vtkIdTypeArray> ControlPointIndices; // store original ID to determine which control point is actually visible
131  vtkSmartPointer<vtkPointSetToLabelHierarchy> OccludedPointSetToLabelHierarchyFilter;
132 
133  vtkSmartPointer<vtkGlyph3DMapper> OccludedGlyphMapper;
134  vtkSmartPointer<vtkLabelPlacementMapper> LabelsMapper;
135  vtkSmartPointer<vtkLabelPlacementMapper> LabelsOccludedMapper;
136 
137  vtkSmartPointer<vtkActor> Actor;
138  vtkSmartPointer<vtkActor> OccludedActor;
139  vtkSmartPointer<vtkActor2D> LabelsActor;
140  vtkSmartPointer<vtkActor2D> LabelsOccludedActor;
141  };
142 
143  ControlPointsPipeline3D* GetControlPointsPipeline(int controlPointType);
144 
145  virtual void UpdateControlPointGlyphOrientation();
146 
147  virtual void UpdateNthPointAndLabelFromMRML(int n);
148 
149  virtual void UpdateAllPointsAndLabelsFromMRML();
150 
157  void UpdateRelativeCoincidentTopologyOffsets(vtkMapper* mapper, vtkMapper* occludedMapper);
159 
160  vtkSmartPointer<vtkCellPicker> AccuratePicker;
161 
162  double TextActorPositionWorld[3];
166 
167  static std::map<vtkRenderer*, vtkSmartPointer<vtkFloatArray> > CachedZBuffers;
168 
169  vtkSmartPointer<vtkCallbackCommand> RenderCompletedCallback;
170  static void OnRenderCompleted(vtkObject* caller, unsigned long event, void* clientData, void* callData);
171  static vtkFloatArray* GetCachedZBuffer(vtkRenderer* renderer);
172 
173 private:
175  void operator=(const vtkSlicerMarkupsWidgetRepresentation3D&) = delete;
176 };
177 
178 #endif
virtual void CanInteract(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2)
Default representation for the markups widget in 3D views.
virtual void UpdateInteractionPipeline()
Update the interaction pipeline.
void UpdateFromMRML(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr) override
Update the representation from markups node.
vtkSmartPointer< vtkCallbackCommand > RenderCompletedCallback
static std::map< vtkRenderer *, vtkSmartPointer< vtkFloatArray > > CachedZBuffers
int RenderOverlay(vtkViewport *viewport) override
vtkTypeBool HasTranslucentPolygonalGeometry() override
int RenderOpaqueGeometry(vtkViewport *viewport) override
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
void ReleaseGraphicsResources(vtkWindow *) override
void PrintSelf(ostream &os, vtkIndent indent) override
void GetActors(vtkPropCollection *) override
Methods to make this class behave as a vtkProp.
virtual void UpdateRelativeCoincidentTopologyOffsets(vtkMapper *mapper)
virtual void SetRenderer(vtkRenderer *ren)
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
vtkSmartPointer< vtkDoubleArray > GlyphOrientationArray
Orientation of the glyphs, represented as an array of quaternions.
extract points that are visible (based on z-buffer calculation)