1 // Created on: 2012-04-02
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IVtkDraw_HighlightAndSelectionPipeline.hxx>
18 // prevent disabling some MSVC warning messages by VTK headers
19 #include <Standard_WarningsDisable.hxx>
20 #include <vtkRenderer.h>
22 #include <vtkPolyDataMapper.h>
23 #include <vtkPolyData.h>
24 #include <vtkAppendPolyData.h>
25 #include <vtkProperty.h>
26 #include <vtkRenderWindow.h>
27 #include <Standard_WarningsRestore.hxx>
29 #include <IVtkOCC_Shape.hxx>
30 #include <IVtkTools_DisplayModeFilter.hxx>
31 #include <IVtkTools_ShapeDataSource.hxx>
32 #include <IVtkTools_ShapeObject.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline,Standard_Transient)
36 //===========================================================
37 // Function : Constructor
39 //===========================================================
41 IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
42 const Standard_Integer theShapeID,
43 const Handle(Prs3d_Drawer)& theDrawerLink)
44 : Standard_Transient()
46 /* ===========================
47 * Allocate involved filters
48 * =========================== */
50 myFilterMap.Bind (Filter_DM_Shape, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
51 myFilterMap.Bind (Filter_DM_Hili, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
52 myFilterMap.Bind (Filter_DM_Sel, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
53 myFilterMap.Bind (Filter_SUB_Hili, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
54 myFilterMap.Bind (Filter_SUB_Sel, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
56 /* ========================
57 * Build primary pipeline
58 * ======================== */
60 myActor = vtkSmartPointer<vtkActor>::New();
61 IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape, theDrawerLink);
62 anIVtkShape->SetId (theShapeID);
63 vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
64 aDataSource->SetShape (anIVtkShape);
66 IVtkTools_DisplayModeFilter*
67 aDMFilter = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape));
69 aDMFilter->AddInputConnection (aDataSource->GetOutputPort());
70 aDMFilter->SetDisplayMode (DM_Wireframe);
72 myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
73 myMapper->AddInputConnection(aDMFilter->GetOutputPort());
74 myActor->SetMapper(myMapper);
75 IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
77 myMapper->ScalarVisibilityOn();
78 myMapper->SetScalarModeToUseCellFieldData();
79 IVtkTools::InitShapeMapper (myMapper);
82 /* =================================
83 * Build pipeline for highlighting
84 * ================================= */
86 IVtkTools_DisplayModeFilter*
87 aDMFilterH = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Hili) );
88 IVtkTools_SubPolyDataFilter*
89 aSUBFilterH = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Hili) );
91 // No highligthing exists initially
92 aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
93 aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort());
95 myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
96 myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
98 // Create non-pickable actor
99 myHiliActor = vtkSmartPointer<vtkActor>::New();
100 myHiliActor->SetPickable(0);
101 myHiliActor->SetVisibility(1);
102 myHiliActor->GetProperty()->SetColor(0, 1, 1);
103 myHiliActor->GetProperty()->SetOpacity(1);
104 myHiliActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
105 myHiliActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
107 // Set maper for actor
108 myHiliActor->SetMapper (myHiliMapper);
109 myHiliMapper->ScalarVisibilityOff();
111 /* ==============================
112 * Build pipeline for selection
113 * ============================== */
115 IVtkTools_DisplayModeFilter*
116 aDMFilterS = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel) );
117 IVtkTools_SubPolyDataFilter*
118 aSUBFilterS = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Sel) );
120 // No highligthing exists initially
121 aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
122 aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort());
124 mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
125 mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
127 // Create non-pickable actor
128 mySelActor = vtkSmartPointer<vtkActor>::New();
129 mySelActor->SetPickable (0);
130 mySelActor->SetVisibility (1);
131 mySelActor->GetProperty()->SetColor (1, 1, 1);
132 mySelActor->GetProperty()->SetOpacity (1);
133 mySelActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
134 mySelActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
136 // Set maper for actor
137 mySelActor->SetMapper (mySelMapper);
138 mySelMapper->ScalarVisibilityOff();
141 //===========================================================
142 // Function : AddToRenderer
144 //===========================================================
145 void IVtkDraw_HighlightAndSelectionPipeline::AddToRenderer (vtkRenderer* theRenderer)
147 theRenderer->AddActor (myActor);
148 theRenderer->AddActor (myHiliActor);
149 theRenderer->AddActor (mySelActor);
152 //===========================================================
153 // Function : RemoveFromRenderer
155 //===========================================================
156 void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* theRenderer)
158 theRenderer->RemoveActor (myActor);
159 theRenderer->RemoveActor (myHiliActor);
160 theRenderer->RemoveActor (mySelActor);
162 vtkSmartPointer<vtkRenderWindow> aWin = theRenderer->GetRenderWindow();
165 myActor->ReleaseGraphicsResources(aWin);
166 myHiliActor->ReleaseGraphicsResources(aWin);
167 mySelActor->ReleaseGraphicsResources(aWin);
171 //===========================================================
172 // Function : ClearHighlightFilters
174 //===========================================================
175 void IVtkDraw_HighlightAndSelectionPipeline::ClearHighlightFilters()
177 this->GetHighlightFilter()->Clear();
178 this->GetHighlightFilter()->SetDoFiltering (true);
179 this->GetHighlightFilter()->Modified();
182 //===========================================================
183 // Function : ClearSelectionFilters
185 //===========================================================
186 void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters()
188 this->GetSelectionFilter()->Clear();
189 this->GetSelectionFilter()->SetDoFiltering (true);
190 this->GetSelectionFilter()->Modified();
193 //===========================================================
194 // Function : GetDisplayModeFilter
196 //===========================================================
197 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
199 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Shape));
202 //===========================================================
203 // Function : GetHighlightFilter
205 //===========================================================
206 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
208 return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Hili));
211 //===========================================================
212 // Function : GetSelectionFilter
214 //===========================================================
215 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
217 return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Sel));
220 //===========================================================
221 // Function : GetHighlightDMFilter
223 //===========================================================
224 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
226 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Hili));
229 //===========================================================
230 // Function : GetSelectionDMFilter
232 //===========================================================
233 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
235 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel));
238 //===========================================================
239 // Function : SharedVerticesSelectionOn
241 //===========================================================
242 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOn()
244 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_True);
245 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_True);
248 //===========================================================
249 // Function : SharedVerticesSelectionOff
251 //===========================================================
252 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOff()
254 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_False);
255 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_False);