Salome HOME
4a5709be100a99c3e6c5142f6c950d27b1b44254
[modules/visu.git] / src / OBJECT / VISU_IsoSurfActor.cxx
1 // Copyright (C) 2007-2011  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 //  VISU OBJECT : interactive object for VISU entities implementation
21 //  File   : VISU_IsoSurfActor.cxx
22 //  Author : Vitaly Smetannikov
23 //  Module : VISU
24 //
25 #include "VISU_IsoSurfActor.h"
26 #include "VISU_PipeLine.hxx"
27 #include "VISU_LabelPointsFilter.hxx"
28
29
30 #include <vtkObjectFactory.h>
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkPolyData.h>
33 #include <vtkActor2D.h>
34 //#include <vtkMaskPoints.h>
35 #include <vtkLabeledDataMapper.h>
36 #include <vtkProperty2D.h>
37 #include <vtkRenderer.h>
38 #include <vtkCellArray.h>
39 #include <vtkPointData.h>
40
41
42
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_IsoSurfActor);
45
46
47 //----------------------------------------------------------------------------
48 VISU_IsoSurfActor::VISU_IsoSurfActor():
49   VISU_ScalarMapAct(),
50   myIsLinesLabeled(true)
51 {
52   myLabelsDataSet = vtkPolyData::New();
53
54 //   myMaskPoints = vtkMaskPoints::New();
55 //   myMaskPoints->SetInput(myLabelsDataSet);
56 //   myMaskPoints->SetOnRatio(100);
57
58   myMaskPoints = VISU_LabelPointsFilter::New();
59   myMaskPoints->SetInput(myLabelsDataSet);
60
61   myLabeledDataMapper = vtkLabeledDataMapper::New();
62   myLabeledDataMapper->SetInput(myMaskPoints->GetOutput());
63   //myLabeledDataMapper->SetLabelFormat("%e");
64   myLabeledDataMapper->SetLabelModeToLabelScalars();
65     
66   myLabels = vtkActor2D::New();
67   myLabels->SetMapper(myLabeledDataMapper);
68   myLabels->GetProperty()->SetColor(1,1,1);
69   myLabels->SetVisibility(myIsLinesLabeled);
70 }
71
72
73 //----------------------------------------------------------------------------
74 VISU_IsoSurfActor::~VISU_IsoSurfActor()
75 {
76   myLabelsDataSet->Delete();
77   myMaskPoints->Delete();
78   myLabeledDataMapper->Delete();
79   myLabels->Delete();
80 }
81
82 //----------------------------------------------------------------------------
83 void VISU_IsoSurfActor::SetLinesLabeled(bool theIsLinesLabeled, int theNbLbl)
84 {
85   myIsLinesLabeled = theIsLinesLabeled;
86   myMaskPoints->SetPointsNb(theNbLbl);
87   Modified();
88 }
89  
90 //----------------------------------------------------------------------------
91 int VISU_IsoSurfActor::GetNbLabels() const 
92
93   return myMaskPoints->GetPointsNb(); 
94 }
95
96
97 //----------------------------------------------------------------------------
98 void VISU_IsoSurfActor::UpdateLabels()
99 {
100   if (myIsLinesLabeled) {
101     vtkDataSet* aDataSet = GetPipeLine()->GetOutput();
102     if (aDataSet != NULL) {
103       unsigned long aTime = myLabelsDataSet->GetMTime();
104       unsigned long anObjTime = GetMTime();
105       if (aTime < anObjTime) {
106         myLabelsDataSet->ShallowCopy(aDataSet);
107         myLabelsDataSet->Modified();
108       }
109     }
110   }
111   myLabels->SetVisibility(myIsLinesLabeled);
112 }
113
114
115 //----------------------------------------------------------------------------
116 void VISU_IsoSurfActor::AddToRender(vtkRenderer* theRenderer)
117 {
118   VISU_ScalarMapAct::AddToRender(theRenderer);
119   theRenderer->AddActor2D(myLabels);
120 }
121
122 //----------------------------------------------------------------------------
123 void VISU_IsoSurfActor::RemoveFromRender(vtkRenderer* theRenderer)
124 {
125   theRenderer->RemoveActor(myLabels);
126   VISU_ScalarMapAct::RemoveFromRender(theRenderer);
127 }
128
129 //From vtkFollower
130 int VISU_IsoSurfActor::RenderOpaqueGeometry(vtkViewport *vp)
131 {
132   UpdateLabels();
133   return VISU_ScalarMapAct::RenderOpaqueGeometry(vp);
134 }
135
136 #if (VTK_XVERSION < 0x050100)
137 int VISU_IsoSurfActor::RenderTranslucentGeometry(vtkViewport *vp)
138 #else
139 int VISU_IsoSurfActor::RenderTranslucentPolygonalGeometry(vtkViewport *vp)
140 #endif
141 {
142   UpdateLabels();
143 #if (VTK_XVERSION < 0x050100)
144   return VISU_ScalarMapAct::RenderTranslucentGeometry(vp);
145 #else
146   return VISU_ScalarMapAct::RenderTranslucentPolygonalGeometry(vp);
147 #endif
148 }
149
150 void VISU_IsoSurfActor::SetVisibility(int theMode){
151   VISU_ScalarMapAct::SetVisibility(theMode);
152   if(GetVisibility())
153     myLabels->VisibilityOn();
154   else
155     myLabels->VisibilityOff();
156   Modified();
157 }
158
159
160 ///!!!! For test purposes only
161 // void VISU_IsoSurfActor::SetMapperInput(vtkDataSet* theDataSet)
162 // {
163 //   VISU_ScalarMapAct::SetMapperInput(theDataSet);
164
165 //   vtkFeatureEdges* aFilter = vtkFeatureEdges::New();
166 //   aFilter->SetInput(VISU_ScalarMapAct::GetInput());
167 //   SetInput(aFilter->GetOutput());
168 // }