]> SALOME platform Git repositories - modules/gui.git/blob - src/VTKViewer/VTKViewer_DataSetMapper.cxx
Salome HOME
711a04ad0b2ddba0478adad1d0b0d2bf4ad5ddc4
[modules/gui.git] / src / VTKViewer / VTKViewer_DataSetMapper.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "VTKViewer_DataSetMapper.h"
21 #include "VTKViewer_PolyDataMapper.h"
22
23 #include <vtkDataSetSurfaceFilter.h>
24 #include <vtkObjectFactory.h>
25
26 vtkStandardNewMacro(VTKViewer_DataSetMapper);
27
28 //----------------------------------------------------------------------------
29 VTKViewer_DataSetMapper::VTKViewer_DataSetMapper()
30 {
31   this->MarkerEnabled = false;
32   this->MarkerType    = VTK::MT_NONE;
33   this->MarkerScale   = VTK::MS_NONE;
34   this->MarkerId      = 0;
35 }
36
37 //----------------------------------------------------------------------------
38 VTKViewer_DataSetMapper::~VTKViewer_DataSetMapper()
39 {
40 }
41
42 //----------------------------------------------------------------------------
43 void VTKViewer_DataSetMapper::Render(vtkRenderer *ren, vtkActor *act)
44 {
45   // just to create VTKViewer_PolyDataMapper instead of vtkPolyDataMapper
46   if( this->PolyDataMapper == NULL )
47   {
48     vtkDataSetSurfaceFilter *gf = vtkDataSetSurfaceFilter::New();
49     VTKViewer_PolyDataMapper *pm = VTKViewer_PolyDataMapper::New();
50     pm->SetInputConnection(gf->GetOutputPort());
51
52     pm->SetMarkerEnabled( this->MarkerEnabled );
53     if( this->MarkerType != VTK::MT_USER )
54       pm->SetMarkerStd( this->MarkerType, this->MarkerScale );
55     else
56       pm->SetMarkerTexture( this->MarkerId, this->MarkerTexture );
57
58     this->GeometryExtractor = gf;
59     this->PolyDataMapper = pm;
60   }
61   vtkDataSetMapper::Render(ren, act);
62 }
63
64 //-----------------------------------------------------------------------------
65 void VTKViewer_DataSetMapper::SetMarkerEnabled( bool theMarkerEnabled )
66 {
67   this->MarkerEnabled = theMarkerEnabled;
68   if( this->PolyDataMapper )
69     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
70       aMapper->SetMarkerEnabled( theMarkerEnabled );
71 }
72
73 //----------------------------------------------------------------------------
74 void VTKViewer_DataSetMapper::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
75 {
76   this->MarkerType = theMarkerType;
77   this->MarkerScale = theMarkerScale;
78   if( this->PolyDataMapper )
79     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
80       aMapper->SetMarkerStd( theMarkerType, theMarkerScale );
81 }
82
83 //----------------------------------------------------------------------------
84 void VTKViewer_DataSetMapper::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
85 {
86   this->MarkerType = VTK::MT_USER;
87   this->MarkerId = theMarkerId;
88   this->MarkerTexture = theMarkerTexture;
89   if( this->PolyDataMapper )
90     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
91       aMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
92 }
93
94 //-----------------------------------------------------------------------------
95 VTK::MarkerType VTKViewer_DataSetMapper::GetMarkerType()
96 {
97   return this->MarkerType;
98 }
99
100 //-----------------------------------------------------------------------------
101 VTK::MarkerScale VTKViewer_DataSetMapper::GetMarkerScale()
102 {
103   return this->MarkerScale;
104 }
105
106 //-----------------------------------------------------------------------------
107 int VTKViewer_DataSetMapper::GetMarkerTexture()
108 {
109   return this->MarkerId;
110 }