52f99d93 |
1 | // Created on: 2012-04-02 |
2 | |
3 | // Copyright (c) 2012-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <IVtkDraw_HighlightAndSelectionPipeline.hxx> |
17 | |
a9660929 |
18 | // prevent disabling some MSVC warning messages by VTK headers |
19 | #ifdef _MSC_VER |
20 | #pragma warning(push) |
21 | #endif |
52f99d93 |
22 | #include <vtkRenderer.h> |
23 | #include <vtkActor.h> |
24 | #include <vtkPolyDataMapper.h> |
25 | #include <vtkPolyData.h> |
26 | #include <vtkAppendPolyData.h> |
27 | #include <vtkProperty.h> |
a2f76b15 |
28 | #include <vtkRenderWindow.h> |
a9660929 |
29 | #ifdef _MSC_VER |
30 | #pragma warning(pop) |
31 | #endif |
52f99d93 |
32 | |
33 | #include <IVtkOCC_Shape.hxx> |
34 | #include <IVtkTools_DisplayModeFilter.hxx> |
35 | #include <IVtkTools_ShapeDataSource.hxx> |
36 | #include <IVtkTools_ShapeObject.hxx> |
37 | |
52f99d93 |
38 | |
92efcf78 |
39 | IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline,Standard_Transient) |
40 | |
52f99d93 |
41 | //=========================================================== |
42 | // Function : Constructor |
43 | // Purpose : |
44 | //=========================================================== |
45 | |
46 | IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape, |
47 | const Standard_Integer theShapeID) |
48 | : Standard_Transient() |
49 | { |
50 | /* =========================== |
51 | * Allocate involved filters |
52 | * =========================== */ |
53 | |
54 | myFilterMap.Bind (Filter_DM_Shape, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New()); |
55 | myFilterMap.Bind (Filter_DM_Hili, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New()); |
56 | myFilterMap.Bind (Filter_DM_Sel, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New()); |
57 | myFilterMap.Bind (Filter_SUB_Hili, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New()); |
58 | myFilterMap.Bind (Filter_SUB_Sel, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New()); |
59 | |
60 | /* ======================== |
61 | * Build primary pipeline |
62 | * ======================== */ |
63 | |
64 | myActor = vtkSmartPointer<vtkActor>::New(); |
65 | IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape); |
66 | anIVtkShape->SetId (theShapeID); |
67 | vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New(); |
a9dde4a3 |
68 | aDataSource->SetShape (anIVtkShape); |
52f99d93 |
69 | |
70 | IVtkTools_DisplayModeFilter* |
71 | aDMFilter = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape)); |
72 | |
73 | aDMFilter->AddInputConnection (aDataSource->GetOutputPort()); |
74 | aDMFilter->SetDisplayMode (DM_Wireframe); |
75 | |
76 | myMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
a2f76b15 |
77 | myMapper->AddInputConnection(aDMFilter->GetOutputPort()); |
78 | myActor->SetMapper(myMapper); |
52f99d93 |
79 | IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor); |
80 | |
81 | myMapper->ScalarVisibilityOn(); |
82 | myMapper->SetScalarModeToUseCellFieldData(); |
83 | IVtkTools::InitShapeMapper (myMapper); |
84 | myMapper->Update(); |
85 | |
86 | /* ================================= |
87 | * Build pipeline for highlighting |
88 | * ================================= */ |
89 | |
90 | IVtkTools_DisplayModeFilter* |
91 | aDMFilterH = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Hili) ); |
92 | IVtkTools_SubPolyDataFilter* |
93 | aSUBFilterH = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Hili) ); |
94 | |
95 | // No highligthing exists initially |
96 | aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() ); |
a2f76b15 |
97 | aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort()); |
52f99d93 |
98 | |
99 | myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
100 | myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() ); |
101 | |
102 | // Create non-pickable actor |
103 | myHiliActor = vtkSmartPointer<vtkActor>::New(); |
104 | myHiliActor->SetPickable(0); |
105 | myHiliActor->SetVisibility(1); |
106 | myHiliActor->GetProperty()->SetColor(0, 1, 1); |
107 | myHiliActor->GetProperty()->SetOpacity(1); |
108 | myHiliActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 ); |
109 | myHiliActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 ); |
110 | |
111 | // Set maper for actor |
112 | myHiliActor->SetMapper (myHiliMapper); |
113 | myHiliMapper->ScalarVisibilityOff(); |
114 | |
115 | /* ============================== |
116 | * Build pipeline for selection |
117 | * ============================== */ |
118 | |
119 | IVtkTools_DisplayModeFilter* |
120 | aDMFilterS = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel) ); |
121 | IVtkTools_SubPolyDataFilter* |
122 | aSUBFilterS = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Sel) ); |
123 | |
124 | // No highligthing exists initially |
125 | aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() ); |
a2f76b15 |
126 | aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort()); |
52f99d93 |
127 | |
128 | mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
129 | mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() ); |
130 | |
131 | // Create non-pickable actor |
132 | mySelActor = vtkSmartPointer<vtkActor>::New(); |
133 | mySelActor->SetPickable (0); |
134 | mySelActor->SetVisibility (1); |
135 | mySelActor->GetProperty()->SetColor (1, 1, 1); |
136 | mySelActor->GetProperty()->SetOpacity (1); |
137 | mySelActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 ); |
138 | mySelActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 ); |
139 | |
140 | // Set maper for actor |
141 | mySelActor->SetMapper (mySelMapper); |
142 | mySelMapper->ScalarVisibilityOff(); |
143 | } |
144 | |
145 | //=========================================================== |
146 | // Function : AddToRenderer |
147 | // Purpose : |
148 | //=========================================================== |
149 | void IVtkDraw_HighlightAndSelectionPipeline::AddToRenderer (vtkRenderer* theRenderer) |
150 | { |
151 | theRenderer->AddActor (myActor); |
152 | theRenderer->AddActor (myHiliActor); |
153 | theRenderer->AddActor (mySelActor); |
154 | } |
155 | |
156 | //=========================================================== |
157 | // Function : RemoveFromRenderer |
158 | // Purpose : |
159 | //=========================================================== |
160 | void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* theRenderer) |
161 | { |
162 | theRenderer->RemoveActor (myActor); |
163 | theRenderer->RemoveActor (myHiliActor); |
164 | theRenderer->RemoveActor (mySelActor); |
a2f76b15 |
165 | |
166 | vtkSmartPointer<vtkRenderWindow> aWin = theRenderer->GetRenderWindow(); |
167 | if (aWin != NULL) |
168 | { |
169 | myActor->ReleaseGraphicsResources(aWin); |
170 | myHiliActor->ReleaseGraphicsResources(aWin); |
171 | mySelActor->ReleaseGraphicsResources(aWin); |
172 | } |
52f99d93 |
173 | } |
174 | |
175 | //=========================================================== |
176 | // Function : ClearHighlightFilters |
177 | // Purpose : |
178 | //=========================================================== |
179 | void IVtkDraw_HighlightAndSelectionPipeline::ClearHighlightFilters() |
180 | { |
181 | this->GetHighlightFilter()->Clear(); |
182 | this->GetHighlightFilter()->SetDoFiltering (true); |
183 | this->GetHighlightFilter()->Modified(); |
184 | } |
185 | |
186 | //=========================================================== |
187 | // Function : ClearSelectionFilters |
188 | // Purpose : |
189 | //=========================================================== |
190 | void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters() |
191 | { |
192 | this->GetSelectionFilter()->Clear(); |
193 | this->GetSelectionFilter()->SetDoFiltering (true); |
194 | this->GetSelectionFilter()->Modified(); |
195 | } |
196 | |
197 | //=========================================================== |
198 | // Function : GetDisplayModeFilter |
199 | // Purpose : |
200 | //=========================================================== |
201 | IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter() |
202 | { |
a2f76b15 |
203 | return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Shape)); |
52f99d93 |
204 | } |
205 | |
206 | //=========================================================== |
207 | // Function : GetHighlightFilter |
208 | // Purpose : |
209 | //=========================================================== |
210 | IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter() |
211 | { |
a2f76b15 |
212 | return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Hili)); |
52f99d93 |
213 | } |
214 | |
215 | //=========================================================== |
216 | // Function : GetSelectionFilter |
217 | // Purpose : |
218 | //=========================================================== |
219 | IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter() |
220 | { |
a2f76b15 |
221 | return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Sel)); |
52f99d93 |
222 | } |
223 | |
224 | //=========================================================== |
225 | // Function : GetHighlightDMFilter |
226 | // Purpose : |
227 | //=========================================================== |
228 | IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter() |
229 | { |
a2f76b15 |
230 | return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Hili)); |
52f99d93 |
231 | } |
232 | |
233 | //=========================================================== |
234 | // Function : GetSelectionDMFilter |
235 | // Purpose : |
236 | //=========================================================== |
237 | IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter() |
238 | { |
a2f76b15 |
239 | return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel)); |
52f99d93 |
240 | } |
241 | |
242 | //=========================================================== |
243 | // Function : SharedVerticesSelectionOn |
244 | // Purpose : |
245 | //=========================================================== |
246 | void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOn() |
247 | { |
248 | this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_True); |
249 | this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_True); |
250 | } |
251 | |
252 | //=========================================================== |
253 | // Function : SharedVerticesSelectionOff |
254 | // Purpose : |
255 | //=========================================================== |
256 | void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOff() |
257 | { |
258 | this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_False); |
259 | this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_False); |
260 | } |