1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_IsoSurfActor.cxx
24 // Author : Vitaly Smetannikov
27 #include "VISU_IsoSurfActor.h"
28 #include "VISU_PipeLine.hxx"
29 #include "VISU_LabelPointsFilter.hxx"
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>
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_IsoSurfActor);
49 //----------------------------------------------------------------------------
50 VISU_IsoSurfActor::VISU_IsoSurfActor():
52 myIsLinesLabeled(true)
54 myLabelsDataSet = vtkPolyData::New();
56 // myMaskPoints = vtkMaskPoints::New();
57 // myMaskPoints->SetInput(myLabelsDataSet);
58 // myMaskPoints->SetOnRatio(100);
60 myMaskPoints = VISU_LabelPointsFilter::New();
61 myMaskPoints->SetInput(myLabelsDataSet);
63 myLabeledDataMapper = vtkLabeledDataMapper::New();
64 myLabeledDataMapper->SetInput(myMaskPoints->GetOutput());
65 //myLabeledDataMapper->SetLabelFormat("%e");
66 myLabeledDataMapper->SetLabelModeToLabelScalars();
68 myLabels = vtkActor2D::New();
69 myLabels->SetMapper(myLabeledDataMapper);
70 myLabels->GetProperty()->SetColor(1,1,1);
71 myLabels->SetVisibility(myIsLinesLabeled);
75 //----------------------------------------------------------------------------
76 VISU_IsoSurfActor::~VISU_IsoSurfActor()
78 myLabelsDataSet->Delete();
79 myMaskPoints->Delete();
80 myLabeledDataMapper->Delete();
84 //----------------------------------------------------------------------------
85 void VISU_IsoSurfActor::SetLinesLabeled(bool theIsLinesLabeled, int theNbLbl)
87 myIsLinesLabeled = theIsLinesLabeled;
88 myMaskPoints->SetPointsNb(theNbLbl);
92 //----------------------------------------------------------------------------
93 int VISU_IsoSurfActor::GetNbLabels() const
95 return myMaskPoints->GetPointsNb();
99 //----------------------------------------------------------------------------
100 void VISU_IsoSurfActor::UpdateLabels()
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();
113 myLabels->SetVisibility(myIsLinesLabeled);
117 //----------------------------------------------------------------------------
118 void VISU_IsoSurfActor::AddToRender(vtkRenderer* theRenderer)
120 VISU_ScalarMapAct::AddToRender(theRenderer);
121 theRenderer->AddActor2D(myLabels);
124 //----------------------------------------------------------------------------
125 void VISU_IsoSurfActor::RemoveFromRender(vtkRenderer* theRenderer)
127 VISU_ScalarMapAct::RemoveFromRender(theRenderer);
128 theRenderer->RemoveActor(myLabels);
132 int VISU_IsoSurfActor::RenderOpaqueGeometry(vtkViewport *vp)
135 return VISU_ScalarMapAct::RenderOpaqueGeometry(vp);
139 int VISU_IsoSurfActor::RenderTranslucentGeometry(vtkViewport *vp)
142 return VISU_ScalarMapAct::RenderTranslucentGeometry(vp);
145 void VISU_IsoSurfActor::SetVisibility(int theMode){
146 VISU_ScalarMapAct::SetVisibility(theMode);
148 myLabels->VisibilityOn();
150 myLabels->VisibilityOff();
155 ///!!!! For test purposes only
156 // void VISU_IsoSurfActor::SetMapperInput(vtkDataSet* theDataSet)
158 // VISU_ScalarMapAct::SetMapperInput(theDataSet);
160 // vtkFeatureEdges* aFilter = vtkFeatureEdges::New();
161 // aFilter->SetInput(VISU_ScalarMapAct::GetInput());
162 // SetInput(aFilter->GetOutput());