Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / OBJECT / VISU_IsoSurfActor.cxx
1 //  Copyright (C) 2007-2010  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   VISU_ScalarMapAct::RemoveFromRender(theRenderer);
126   theRenderer->RemoveActor(myLabels);
127 }
128
129 //From vtkFollower
130 int VISU_IsoSurfActor::RenderOpaqueGeometry(vtkViewport *vp)
131 {
132   UpdateLabels();
133   return VISU_ScalarMapAct::RenderOpaqueGeometry(vp);
134 }
135
136
137 int VISU_IsoSurfActor::RenderTranslucentGeometry(vtkViewport *vp)
138 {
139   UpdateLabels();
140   return VISU_ScalarMapAct::RenderTranslucentGeometry(vp);
141 }
142
143 void VISU_IsoSurfActor::SetVisibility(int theMode){
144   VISU_ScalarMapAct::SetVisibility(theMode);
145   if(GetVisibility())
146     myLabels->VisibilityOn();
147   else
148     myLabels->VisibilityOff();
149   Modified();
150 }
151
152
153 ///!!!! For test purposes only
154 // void VISU_IsoSurfActor::SetMapperInput(vtkDataSet* theDataSet)
155 // {
156 //   VISU_ScalarMapAct::SetMapperInput(theDataSet);
157
158 //   vtkFeatureEdges* aFilter = vtkFeatureEdges::New();
159 //   aFilter->SetInput(VISU_ScalarMapAct::GetInput());
160 //   SetInput(aFilter->GetOutput());
161 // }