1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU OBJECT : interactive object for VISU entities implementation
21 // File : VISU_IsoSurfActor.cxx
22 // Author : Vitaly Smetannikov
25 #include "VISU_IsoSurfActor.h"
26 #include "VISU_PipeLine.hxx"
27 #include "VISU_LabelPointsFilter.hxx"
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>
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_IsoSurfActor);
47 //----------------------------------------------------------------------------
48 VISU_IsoSurfActor::VISU_IsoSurfActor():
50 myIsLinesLabeled(true)
52 myLabelsDataSet = vtkPolyData::New();
54 // myMaskPoints = vtkMaskPoints::New();
55 // myMaskPoints->SetInput(myLabelsDataSet);
56 // myMaskPoints->SetOnRatio(100);
58 myMaskPoints = VISU_LabelPointsFilter::New();
59 myMaskPoints->SetInput(myLabelsDataSet);
61 myLabeledDataMapper = vtkLabeledDataMapper::New();
62 myLabeledDataMapper->SetInput(myMaskPoints->GetOutput());
63 //myLabeledDataMapper->SetLabelFormat("%e");
64 myLabeledDataMapper->SetLabelModeToLabelScalars();
66 myLabels = vtkActor2D::New();
67 myLabels->SetMapper(myLabeledDataMapper);
68 myLabels->GetProperty()->SetColor(1,1,1);
69 myLabels->SetVisibility(myIsLinesLabeled);
73 //----------------------------------------------------------------------------
74 VISU_IsoSurfActor::~VISU_IsoSurfActor()
76 myLabelsDataSet->Delete();
77 myMaskPoints->Delete();
78 myLabeledDataMapper->Delete();
82 //----------------------------------------------------------------------------
83 void VISU_IsoSurfActor::SetLinesLabeled(bool theIsLinesLabeled, int theNbLbl)
85 myIsLinesLabeled = theIsLinesLabeled;
86 myMaskPoints->SetPointsNb(theNbLbl);
90 //----------------------------------------------------------------------------
91 int VISU_IsoSurfActor::GetNbLabels() const
93 return myMaskPoints->GetPointsNb();
97 //----------------------------------------------------------------------------
98 void VISU_IsoSurfActor::UpdateLabels()
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();
111 myLabels->SetVisibility(myIsLinesLabeled);
115 //----------------------------------------------------------------------------
116 void VISU_IsoSurfActor::AddToRender(vtkRenderer* theRenderer)
118 VISU_ScalarMapAct::AddToRender(theRenderer);
119 theRenderer->AddActor2D(myLabels);
122 //----------------------------------------------------------------------------
123 void VISU_IsoSurfActor::RemoveFromRender(vtkRenderer* theRenderer)
125 VISU_ScalarMapAct::RemoveFromRender(theRenderer);
126 theRenderer->RemoveActor(myLabels);
130 int VISU_IsoSurfActor::RenderOpaqueGeometry(vtkViewport *vp)
133 return VISU_ScalarMapAct::RenderOpaqueGeometry(vp);
137 int VISU_IsoSurfActor::RenderTranslucentGeometry(vtkViewport *vp)
140 return VISU_ScalarMapAct::RenderTranslucentGeometry(vp);
143 void VISU_IsoSurfActor::SetVisibility(int theMode){
144 VISU_ScalarMapAct::SetVisibility(theMode);
146 myLabels->VisibilityOn();
148 myLabels->VisibilityOff();
153 ///!!!! For test purposes only
154 // void VISU_IsoSurfActor::SetMapperInput(vtkDataSet* theDataSet)
156 // VISU_ScalarMapAct::SetMapperInput(theDataSet);
158 // vtkFeatureEdges* aFilter = vtkFeatureEdges::New();
159 // aFilter->SetInput(VISU_ScalarMapAct::GetInput());
160 // SetInput(aFilter->GetOutput());