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>
25 #include <IVtkOCC_Shape.hxx>
26 #include <IVtkTools_DisplayModeFilter.hxx>
27 #include <IVtkTools_ShapeDataSource.hxx>
28 #include <IVtkTools_ShapeObject.hxx>
30 IMPLEMENT_STANDARD_HANDLE(IVtkDraw_HighlightAndSelectionPipeline, Standard_Transient)
31 IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline, Standard_Transient)
33 //===========================================================
34 // Function : Constructor
36 //===========================================================
38 IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
39 const Standard_Integer theShapeID)
40 : Standard_Transient()
42 /* ===========================
43 * Allocate involved filters
44 * =========================== */
46 myFilterMap.Bind (Filter_DM_Shape, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
47 myFilterMap.Bind (Filter_DM_Hili, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
48 myFilterMap.Bind (Filter_DM_Sel, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
49 myFilterMap.Bind (Filter_SUB_Hili, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
50 myFilterMap.Bind (Filter_SUB_Sel, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
52 /* ========================
53 * Build primary pipeline
54 * ======================== */
56 myActor = vtkSmartPointer<vtkActor>::New();
57 IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape);
58 anIVtkShape->SetId (theShapeID);
59 vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
60 aDataSource->SetShape (IVtkOCC_Shape::Handle::DownCast (anIVtkShape) );
62 IVtkTools_DisplayModeFilter*
63 aDMFilter = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape));
65 aDMFilter->AddInputConnection (aDataSource->GetOutputPort());
66 aDMFilter->SetDisplayMode (DM_Wireframe);
68 myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
69 myMapper->AddInputConnection (aDMFilter->GetOutputPort());
70 myActor->SetMapper (myMapper);
71 IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
73 myMapper->ScalarVisibilityOn();
74 myMapper->SetScalarModeToUseCellFieldData();
75 IVtkTools::InitShapeMapper (myMapper);
78 /* =================================
79 * Build pipeline for highlighting
80 * ================================= */
82 IVtkTools_DisplayModeFilter*
83 aDMFilterH = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Hili) );
84 IVtkTools_SubPolyDataFilter*
85 aSUBFilterH = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Hili) );
87 // No highligthing exists initially
88 aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
89 aDMFilterH->SetInputConnection (aSUBFilterH->GetOutputPort() );
91 myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
92 myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
94 // Create non-pickable actor
95 myHiliActor = vtkSmartPointer<vtkActor>::New();
96 myHiliActor->SetPickable(0);
97 myHiliActor->SetVisibility(1);
98 myHiliActor->GetProperty()->SetColor(0, 1, 1);
99 myHiliActor->GetProperty()->SetOpacity(1);
100 myHiliActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
101 myHiliActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
103 // Set maper for actor
104 myHiliActor->SetMapper (myHiliMapper);
105 myHiliMapper->ScalarVisibilityOff();
107 /* ==============================
108 * Build pipeline for selection
109 * ============================== */
111 IVtkTools_DisplayModeFilter*
112 aDMFilterS = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel) );
113 IVtkTools_SubPolyDataFilter*
114 aSUBFilterS = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Sel) );
116 // No highligthing exists initially
117 aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
118 aDMFilterS->SetInputConnection (aSUBFilterS->GetOutputPort() );
120 mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
121 mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
123 // Create non-pickable actor
124 mySelActor = vtkSmartPointer<vtkActor>::New();
125 mySelActor->SetPickable (0);
126 mySelActor->SetVisibility (1);
127 mySelActor->GetProperty()->SetColor (1, 1, 1);
128 mySelActor->GetProperty()->SetOpacity (1);
129 mySelActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
130 mySelActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
132 // Set maper for actor
133 mySelActor->SetMapper (mySelMapper);
134 mySelMapper->ScalarVisibilityOff();
137 //===========================================================
138 // Function : AddToRenderer
140 //===========================================================
141 void IVtkDraw_HighlightAndSelectionPipeline::AddToRenderer (vtkRenderer* theRenderer)
143 theRenderer->AddActor (myActor);
144 theRenderer->AddActor (myHiliActor);
145 theRenderer->AddActor (mySelActor);
148 //===========================================================
149 // Function : RemoveFromRenderer
151 //===========================================================
152 void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* theRenderer)
154 theRenderer->RemoveActor (myActor);
155 theRenderer->RemoveActor (myHiliActor);
156 theRenderer->RemoveActor (mySelActor);
159 //===========================================================
160 // Function : ClearHighlightFilters
162 //===========================================================
163 void IVtkDraw_HighlightAndSelectionPipeline::ClearHighlightFilters()
165 this->GetHighlightFilter()->Clear();
166 this->GetHighlightFilter()->SetDoFiltering (true);
167 this->GetHighlightFilter()->Modified();
170 //===========================================================
171 // Function : ClearSelectionFilters
173 //===========================================================
174 void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters()
176 this->GetSelectionFilter()->Clear();
177 this->GetSelectionFilter()->SetDoFiltering (true);
178 this->GetSelectionFilter()->Modified();
181 //===========================================================
182 // Function : GetDisplayModeFilter
184 //===========================================================
185 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
187 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape) );
190 //===========================================================
191 // Function : GetHighlightFilter
193 //===========================================================
194 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
196 return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Hili) );
199 //===========================================================
200 // Function : GetSelectionFilter
202 //===========================================================
203 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
205 return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Sel) );
208 //===========================================================
209 // Function : GetHighlightDMFilter
211 //===========================================================
212 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
214 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find (Filter_DM_Hili) );
217 //===========================================================
218 // Function : GetSelectionDMFilter
220 //===========================================================
221 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
223 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel));
226 //===========================================================
227 // Function : SharedVerticesSelectionOn
229 //===========================================================
230 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOn()
232 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_True);
233 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_True);
236 //===========================================================
237 // Function : SharedVerticesSelectionOff
239 //===========================================================
240 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOff()
242 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_False);
243 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_False);