Salome HOME
9f6856878e1f07bc46b5cd0e8ae577bf8238e1e2
[modules/gui.git] / src / VTKViewer / VTKViewer_DataSetMapper.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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->BallEnabled = false;
33   this->BallScale = 1;
34   this->MarkerType    = VTK::MT_NONE;
35   this->MarkerScale   = VTK::MS_NONE;
36   this->MarkerId      = 0;
37 }
38
39 //----------------------------------------------------------------------------
40 VTKViewer_DataSetMapper::~VTKViewer_DataSetMapper()
41 {
42 }
43
44 //----------------------------------------------------------------------------
45 void VTKViewer_DataSetMapper::Render(vtkRenderer *ren, vtkActor *act)
46 {
47   // just to create VTKViewer_PolyDataMapper instead of vtkPolyDataMapper
48   if( this->PolyDataMapper == NULL )
49   {
50     vtkDataSetSurfaceFilter *gf = vtkDataSetSurfaceFilter::New();
51     VTKViewer_PolyDataMapper *pm = VTKViewer_PolyDataMapper::New();
52     pm->SetInputConnection(gf->GetOutputPort());
53
54     pm->SetMarkerEnabled( this->MarkerEnabled );
55     if( this->MarkerType != VTK::MT_USER )
56       pm->SetMarkerStd( this->MarkerType, this->MarkerScale );
57     else
58       pm->SetMarkerTexture( this->MarkerId, this->MarkerTexture );
59     pm->SetBallEnabled( this->BallEnabled );
60     pm->SetBallScale( this->BallScale );
61     
62     this->GeometryExtractor = gf;
63     this->PolyDataMapper = pm;
64   }
65   vtkDataSetMapper::Render(ren, act);
66 }
67
68 //-----------------------------------------------------------------------------
69 void VTKViewer_DataSetMapper::SetMarkerEnabled( bool theMarkerEnabled )
70 {
71   this->MarkerEnabled = theMarkerEnabled;
72   if( this->PolyDataMapper )
73     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
74       aMapper->SetMarkerEnabled( theMarkerEnabled );
75 }
76
77
78 //-----------------------------------------------------------------------------
79 void VTKViewer_DataSetMapper::SetBallEnabled( bool theBallEnabled )
80 {
81   this->BallEnabled = theBallEnabled;
82   if( this->PolyDataMapper )
83     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
84       aMapper->SetBallEnabled( theBallEnabled );
85 }
86
87 //-----------------------------------------------------------------------------
88 void VTKViewer_DataSetMapper::SetBallScale( double theBallScale )
89 {
90   this->BallScale = theBallScale;
91   if( this->PolyDataMapper )
92     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
93       aMapper->SetBallScale( theBallScale );
94 }
95
96 //----------------------------------------------------------------------------
97 void VTKViewer_DataSetMapper::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
98 {
99   this->MarkerType = theMarkerType;
100   this->MarkerScale = theMarkerScale;
101   if( this->PolyDataMapper )
102     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
103       aMapper->SetMarkerStd( theMarkerType, theMarkerScale );
104 }
105
106 //----------------------------------------------------------------------------
107 void VTKViewer_DataSetMapper::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
108 {
109   this->MarkerType = VTK::MT_USER;
110   this->MarkerId = theMarkerId;
111   this->MarkerTexture = theMarkerTexture;
112   if( this->PolyDataMapper )
113     if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>( this->PolyDataMapper ) )
114       aMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
115 }
116
117 //-----------------------------------------------------------------------------
118 VTK::MarkerType VTKViewer_DataSetMapper::GetMarkerType()
119 {
120   return this->MarkerType;
121 }
122
123 //-----------------------------------------------------------------------------
124 VTK::MarkerScale VTKViewer_DataSetMapper::GetMarkerScale()
125 {
126   return this->MarkerScale;
127 }
128
129 //-----------------------------------------------------------------------------
130 int VTKViewer_DataSetMapper::GetMarkerTexture()
131 {
132   return this->MarkerId;
133 }