Salome HOME
312b14d53702dd0888b4bb8c84073ecf82c42b33
[modules/visu.git] / src / OBJECT / VISU_IsoSurfActor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_IsoSurfActor.cxx
24 //  Author : Vitaly Smetannikov
25 //  Module : VISU
26 //
27 #include "VISU_IsoSurfActor.h"
28 #include "VISU_PipeLine.hxx"
29 #include "VISU_LabelPointsFilter.hxx"
30
31
32 #include <vtkObjectFactory.h>
33 #include <vtkUnstructuredGrid.h>
34 #include <vtkPolyData.h>
35 #include <vtkActor2D.h>
36 //#include <vtkMaskPoints.h>
37 #include <vtkLabeledDataMapper.h>
38 #include <vtkProperty2D.h>
39 #include <vtkRenderer.h>
40 #include <vtkCellArray.h>
41 #include <vtkPointData.h>
42
43
44
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_IsoSurfActor);
47
48
49 //----------------------------------------------------------------------------
50 VISU_IsoSurfActor::VISU_IsoSurfActor():
51   VISU_ScalarMapAct(),
52   myIsLinesLabeled(true)
53 {
54   myLabelsDataSet = vtkPolyData::New();
55
56 //   myMaskPoints = vtkMaskPoints::New();
57 //   myMaskPoints->SetInput(myLabelsDataSet);
58 //   myMaskPoints->SetOnRatio(100);
59
60   myMaskPoints = VISU_LabelPointsFilter::New();
61   myMaskPoints->SetInput(myLabelsDataSet);
62
63   myLabeledDataMapper = vtkLabeledDataMapper::New();
64   myLabeledDataMapper->SetInput(myMaskPoints->GetOutput());
65   //myLabeledDataMapper->SetLabelFormat("%e");
66   myLabeledDataMapper->SetLabelModeToLabelScalars();
67     
68   myLabels = vtkActor2D::New();
69   myLabels->SetMapper(myLabeledDataMapper);
70   myLabels->GetProperty()->SetColor(1,1,1);
71   myLabels->SetVisibility(myIsLinesLabeled);
72 }
73
74
75 //----------------------------------------------------------------------------
76 VISU_IsoSurfActor::~VISU_IsoSurfActor()
77 {
78   myLabelsDataSet->Delete();
79   myMaskPoints->Delete();
80   myLabeledDataMapper->Delete();
81   myLabels->Delete();
82 }
83
84 //----------------------------------------------------------------------------
85 void VISU_IsoSurfActor::SetLinesLabeled(bool theIsLinesLabeled, int theNbLbl)
86 {
87   myIsLinesLabeled = theIsLinesLabeled;
88   myMaskPoints->SetPointsNb(theNbLbl);
89   Modified();
90 }
91  
92 //----------------------------------------------------------------------------
93 int VISU_IsoSurfActor::GetNbLabels() const 
94
95   return myMaskPoints->GetPointsNb(); 
96 }
97
98
99 //----------------------------------------------------------------------------
100 void VISU_IsoSurfActor::UpdateLabels()
101 {
102   if (myIsLinesLabeled) {
103     vtkDataSet* aDataSet = GetPipeLine()->GetOutput();
104     if (aDataSet != NULL) {
105       unsigned long aTime = myLabelsDataSet->GetMTime();
106       unsigned long anObjTime = GetMTime();
107       if (aTime < anObjTime) {
108         myLabelsDataSet->ShallowCopy(aDataSet);
109         myLabelsDataSet->Modified();
110       }
111     }
112   }
113   myLabels->SetVisibility(myIsLinesLabeled);
114 }
115
116
117 //----------------------------------------------------------------------------
118 void VISU_IsoSurfActor::AddToRender(vtkRenderer* theRenderer)
119 {
120   VISU_ScalarMapAct::AddToRender(theRenderer);
121   theRenderer->AddActor2D(myLabels);
122 }
123
124 //----------------------------------------------------------------------------
125 void VISU_IsoSurfActor::RemoveFromRender(vtkRenderer* theRenderer)
126 {
127   VISU_ScalarMapAct::RemoveFromRender(theRenderer);
128   theRenderer->RemoveActor(myLabels);
129 }
130
131 //From vtkFollower
132 int VISU_IsoSurfActor::RenderOpaqueGeometry(vtkViewport *vp)
133 {
134   UpdateLabels();
135   return VISU_ScalarMapAct::RenderOpaqueGeometry(vp);
136 }
137
138
139 int VISU_IsoSurfActor::RenderTranslucentGeometry(vtkViewport *vp)
140 {
141   UpdateLabels();
142   return VISU_ScalarMapAct::RenderTranslucentGeometry(vp);
143 }
144
145 void VISU_IsoSurfActor::SetVisibility(int theMode){
146   VISU_ScalarMapAct::SetVisibility(theMode);
147   if(GetVisibility())
148     myLabels->VisibilityOn();
149   else
150     myLabels->VisibilityOff();
151   Modified();
152 }
153
154
155 ///!!!! For test purposes only
156 // void VISU_IsoSurfActor::SetMapperInput(vtkDataSet* theDataSet)
157 // {
158 //   VISU_ScalarMapAct::SetMapperInput(theDataSet);
159
160 //   vtkFeatureEdges* aFilter = vtkFeatureEdges::New();
161 //   aFilter->SetInput(VISU_ScalarMapAct::GetInput());
162 //   SetInput(aFilter->GetOutput());
163 // }