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 #include <vtkRenderer.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkPolyData.h>
22 #include <vtkAppendPolyData.h>
23 #include <vtkProperty.h>
24 #include <vtkRenderWindow.h>
26 #include <IVtkOCC_Shape.hxx>
27 #include <IVtkTools_DisplayModeFilter.hxx>
28 #include <IVtkTools_ShapeDataSource.hxx>
29 #include <IVtkTools_ShapeObject.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline,Standard_Transient)
34 //===========================================================
35 // Function : Constructor
37 //===========================================================
39 IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
40 const Standard_Integer theShapeID)
41 : Standard_Transient()
43 /* ===========================
44 * Allocate involved filters
45 * =========================== */
47 myFilterMap.Bind (Filter_DM_Shape, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
48 myFilterMap.Bind (Filter_DM_Hili, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
49 myFilterMap.Bind (Filter_DM_Sel, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
50 myFilterMap.Bind (Filter_SUB_Hili, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
51 myFilterMap.Bind (Filter_SUB_Sel, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
53 /* ========================
54 * Build primary pipeline
55 * ======================== */
57 myActor = vtkSmartPointer<vtkActor>::New();
58 IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape);
59 anIVtkShape->SetId (theShapeID);
60 vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
61 aDataSource->SetShape (anIVtkShape);
63 IVtkTools_DisplayModeFilter*
64 aDMFilter = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape));
66 aDMFilter->AddInputConnection (aDataSource->GetOutputPort());
67 aDMFilter->SetDisplayMode (DM_Wireframe);
69 myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
70 myMapper->AddInputConnection(aDMFilter->GetOutputPort());
71 myActor->SetMapper(myMapper);
72 IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
74 myMapper->ScalarVisibilityOn();
75 myMapper->SetScalarModeToUseCellFieldData();
76 IVtkTools::InitShapeMapper (myMapper);
79 /* =================================
80 * Build pipeline for highlighting
81 * ================================= */
83 IVtkTools_DisplayModeFilter*
84 aDMFilterH = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Hili) );
85 IVtkTools_SubPolyDataFilter*
86 aSUBFilterH = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Hili) );
88 // No highligthing exists initially
89 aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
90 aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort());
92 myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
93 myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
95 // Create non-pickable actor
96 myHiliActor = vtkSmartPointer<vtkActor>::New();
97 myHiliActor->SetPickable(0);
98 myHiliActor->SetVisibility(1);
99 myHiliActor->GetProperty()->SetColor(0, 1, 1);
100 myHiliActor->GetProperty()->SetOpacity(1);
101 myHiliActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
102 myHiliActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
104 // Set maper for actor
105 myHiliActor->SetMapper (myHiliMapper);
106 myHiliMapper->ScalarVisibilityOff();
108 /* ==============================
109 * Build pipeline for selection
110 * ============================== */
112 IVtkTools_DisplayModeFilter*
113 aDMFilterS = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel) );
114 IVtkTools_SubPolyDataFilter*
115 aSUBFilterS = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Sel) );
117 // No highligthing exists initially
118 aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
119 aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort());
121 mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
122 mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
124 // Create non-pickable actor
125 mySelActor = vtkSmartPointer<vtkActor>::New();
126 mySelActor->SetPickable (0);
127 mySelActor->SetVisibility (1);
128 mySelActor->GetProperty()->SetColor (1, 1, 1);
129 mySelActor->GetProperty()->SetOpacity (1);
130 mySelActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
131 mySelActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
133 // Set maper for actor
134 mySelActor->SetMapper (mySelMapper);
135 mySelMapper->ScalarVisibilityOff();
138 //===========================================================
139 // Function : AddToRenderer
141 //===========================================================
142 void IVtkDraw_HighlightAndSelectionPipeline::AddToRenderer (vtkRenderer* theRenderer)
144 theRenderer->AddActor (myActor);
145 theRenderer->AddActor (myHiliActor);
146 theRenderer->AddActor (mySelActor);
149 //===========================================================
150 // Function : RemoveFromRenderer
152 //===========================================================
153 void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* theRenderer)
155 theRenderer->RemoveActor (myActor);
156 theRenderer->RemoveActor (myHiliActor);
157 theRenderer->RemoveActor (mySelActor);
159 vtkSmartPointer<vtkRenderWindow> aWin = theRenderer->GetRenderWindow();
162 myActor->ReleaseGraphicsResources(aWin);
163 myHiliActor->ReleaseGraphicsResources(aWin);
164 mySelActor->ReleaseGraphicsResources(aWin);
168 //===========================================================
169 // Function : ClearHighlightFilters
171 //===========================================================
172 void IVtkDraw_HighlightAndSelectionPipeline::ClearHighlightFilters()
174 this->GetHighlightFilter()->Clear();
175 this->GetHighlightFilter()->SetDoFiltering (true);
176 this->GetHighlightFilter()->Modified();
179 //===========================================================
180 // Function : ClearSelectionFilters
182 //===========================================================
183 void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters()
185 this->GetSelectionFilter()->Clear();
186 this->GetSelectionFilter()->SetDoFiltering (true);
187 this->GetSelectionFilter()->Modified();
190 //===========================================================
191 // Function : GetDisplayModeFilter
193 //===========================================================
194 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
196 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Shape));
199 //===========================================================
200 // Function : GetHighlightFilter
202 //===========================================================
203 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
205 return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Hili));
208 //===========================================================
209 // Function : GetSelectionFilter
211 //===========================================================
212 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
214 return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Sel));
217 //===========================================================
218 // Function : GetHighlightDMFilter
220 //===========================================================
221 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
223 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Hili));
226 //===========================================================
227 // Function : GetSelectionDMFilter
229 //===========================================================
230 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
232 return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel));
235 //===========================================================
236 // Function : SharedVerticesSelectionOn
238 //===========================================================
239 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOn()
241 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_True);
242 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_True);
245 //===========================================================
246 // Function : SharedVerticesSelectionOff
248 //===========================================================
249 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOff()
251 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_False);
252 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_False);