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>
31 //===========================================================
32 // Function : Constructor
34 //===========================================================
36 IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
37 const Standard_Integer theShapeID)
38 : Standard_Transient()
40 /* ===========================
41 * Allocate involved filters
42 * =========================== */
44 myFilterMap.Bind (Filter_DM_Shape, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
45 myFilterMap.Bind (Filter_DM_Hili, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
46 myFilterMap.Bind (Filter_DM_Sel, vtkSmartPointer<IVtkTools_DisplayModeFilter>::New());
47 myFilterMap.Bind (Filter_SUB_Hili, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
48 myFilterMap.Bind (Filter_SUB_Sel, vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New());
50 /* ========================
51 * Build primary pipeline
52 * ======================== */
54 myActor = vtkSmartPointer<vtkActor>::New();
55 IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape);
56 anIVtkShape->SetId (theShapeID);
57 vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
58 aDataSource->SetShape (IVtkOCC_Shape::Handle::DownCast (anIVtkShape) );
60 IVtkTools_DisplayModeFilter*
61 aDMFilter = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape));
63 aDMFilter->AddInputConnection (aDataSource->GetOutputPort());
64 aDMFilter->SetDisplayMode (DM_Wireframe);
66 myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
67 myMapper->AddInputConnection (aDMFilter->GetOutputPort());
68 myActor->SetMapper (myMapper);
69 IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
71 myMapper->ScalarVisibilityOn();
72 myMapper->SetScalarModeToUseCellFieldData();
73 IVtkTools::InitShapeMapper (myMapper);
76 /* =================================
77 * Build pipeline for highlighting
78 * ================================= */
80 IVtkTools_DisplayModeFilter*
81 aDMFilterH = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Hili) );
82 IVtkTools_SubPolyDataFilter*
83 aSUBFilterH = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Hili) );
85 // No highligthing exists initially
86 aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
87 aDMFilterH->SetInputConnection (aSUBFilterH->GetOutputPort() );
89 myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
90 myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
92 // Create non-pickable actor
93 myHiliActor = vtkSmartPointer<vtkActor>::New();
94 myHiliActor->SetPickable(0);
95 myHiliActor->SetVisibility(1);
96 myHiliActor->GetProperty()->SetColor(0, 1, 1);
97 myHiliActor->GetProperty()->SetOpacity(1);
98 myHiliActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
99 myHiliActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
101 // Set maper for actor
102 myHiliActor->SetMapper (myHiliMapper);
103 myHiliMapper->ScalarVisibilityOff();
105 /* ==============================
106 * Build pipeline for selection
107 * ============================== */
109 IVtkTools_DisplayModeFilter*
110 aDMFilterS = IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel) );
111 IVtkTools_SubPolyDataFilter*
112 aSUBFilterS = IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find(Filter_SUB_Sel) );
114 // No highligthing exists initially
115 aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
116 aDMFilterS->SetInputConnection (aSUBFilterS->GetOutputPort() );
118 mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
119 mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
121 // Create non-pickable actor
122 mySelActor = vtkSmartPointer<vtkActor>::New();
123 mySelActor->SetPickable (0);
124 mySelActor->SetVisibility (1);
125 mySelActor->GetProperty()->SetColor (1, 1, 1);
126 mySelActor->GetProperty()->SetOpacity (1);
127 mySelActor->GetProperty()->SetPointSize (myHiliActor->GetProperty()->GetPointSize() + 4 );
128 mySelActor->GetProperty()->SetLineWidth (myHiliActor->GetProperty()->GetLineWidth() + 2 );
130 // Set maper for actor
131 mySelActor->SetMapper (mySelMapper);
132 mySelMapper->ScalarVisibilityOff();
135 //===========================================================
136 // Function : AddToRenderer
138 //===========================================================
139 void IVtkDraw_HighlightAndSelectionPipeline::AddToRenderer (vtkRenderer* theRenderer)
141 theRenderer->AddActor (myActor);
142 theRenderer->AddActor (myHiliActor);
143 theRenderer->AddActor (mySelActor);
146 //===========================================================
147 // Function : RemoveFromRenderer
149 //===========================================================
150 void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* theRenderer)
152 theRenderer->RemoveActor (myActor);
153 theRenderer->RemoveActor (myHiliActor);
154 theRenderer->RemoveActor (mySelActor);
157 //===========================================================
158 // Function : ClearHighlightFilters
160 //===========================================================
161 void IVtkDraw_HighlightAndSelectionPipeline::ClearHighlightFilters()
163 this->GetHighlightFilter()->Clear();
164 this->GetHighlightFilter()->SetDoFiltering (true);
165 this->GetHighlightFilter()->Modified();
168 //===========================================================
169 // Function : ClearSelectionFilters
171 //===========================================================
172 void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters()
174 this->GetSelectionFilter()->Clear();
175 this->GetSelectionFilter()->SetDoFiltering (true);
176 this->GetSelectionFilter()->Modified();
179 //===========================================================
180 // Function : GetDisplayModeFilter
182 //===========================================================
183 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
185 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape) );
188 //===========================================================
189 // Function : GetHighlightFilter
191 //===========================================================
192 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
194 return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Hili) );
197 //===========================================================
198 // Function : GetSelectionFilter
200 //===========================================================
201 IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
203 return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Sel) );
206 //===========================================================
207 // Function : GetHighlightDMFilter
209 //===========================================================
210 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
212 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find (Filter_DM_Hili) );
215 //===========================================================
216 // Function : GetSelectionDMFilter
218 //===========================================================
219 IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
221 return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel));
224 //===========================================================
225 // Function : SharedVerticesSelectionOn
227 //===========================================================
228 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOn()
230 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_True);
231 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_True);
234 //===========================================================
235 // Function : SharedVerticesSelectionOff
237 //===========================================================
238 void IVtkDraw_HighlightAndSelectionPipeline::SharedVerticesSelectionOff()
240 this->GetHighlightDMFilter()->SetDisplaySharedVertices (Standard_False);
241 this->GetSelectionDMFilter()->SetDisplaySharedVertices (Standard_False);