1 // Copyright (C) 2007-2013 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
23 #include "HYDROGUI_VTKPrsBathymetry.h"
25 #include <HYDROData_Entity.h>
26 #include <HYDROData_Tool.h>
28 #include <SALOME_Actor.h>
30 #include <vtkDoubleArray.h>
31 #include <vtkPoints.h>
32 #include <vtkPolyData.h>
33 #include <vtkPointData.h>
34 #include <vtkPolyDataMapper.h>
35 #include <vtkVertex.h>
36 #include <vtkLookupTable.h>
43 #define HUE_START 0.69
45 #define SATURATION_START 1.0
46 #define SATURATION_END 0.4
48 //=======================================================================
49 // name : HYDROGUI_VTKPrsBathymetry
50 // Purpose : Constructor
51 //=======================================================================
52 HYDROGUI_VTKPrsBathymetry::HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject )
53 : HYDROGUI_VTKPrs( theObject )
57 //=======================================================================
58 // name : HYDROGUI_VTKPrsBathymetry
59 // Purpose : Destructor
60 //=======================================================================
61 HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry()
65 //================================================================
68 //================================================================
69 void HYDROGUI_VTKPrsBathymetry::compute()
71 if ( !getObject().IsNull() )
73 Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
74 if ( !aBathymetry.IsNull() )
76 HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
77 int aNbPoints = anAltPoints.length();
79 HYDROData_Bathymetry::AltitudePoint anAltPnt;
80 vtkPoints* aPoints = vtkPoints::New();
81 aPoints->SetNumberOfPoints( aNbPoints );
83 vtkPolyData* aVertexGrid = vtkPolyData::New();
84 aVertexGrid->Allocate( aNbPoints );
86 vtkDoubleArray* aZValues = vtkDoubleArray::New();
87 aZValues->Allocate( aNbPoints );
89 vtkVertex* aVertex = vtkVertex::New();
92 int anInvalidZ = aBathymetry->GetInvalidAltitude();
93 for (int i = 0; i < aNbPoints; i++ )
95 anAltPnt = anAltPoints.at( i );
97 if ( ValuesLessEquals( aZ, anInvalidZ ) )
105 aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), aZ );
106 aVertex->GetPointIds()->SetId( 0, i );
107 aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
108 aZValues->InsertNextValue( aZ );
113 aVertexGrid->SetPoints( aPoints );
114 aVertexGrid->GetPointData()->SetScalars( aZValues );
116 vtkLookupTable* aLut = vtkLookupTable::New();
117 aLut->SetHueRange( HUE_START, HUE_END );
118 aLut->SetSaturationRange( SATURATION_START, SATURATION_END );
119 aLut->SetTableRange( Z_MIN, Z_MAX );
120 aLut->SetValueRange( 1.0, 1.0 );
121 aLut->SetAlphaRange( 1.0, 1.0 );
122 aLut->SetNumberOfColors( NB_COLORS );
125 vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
126 aMapper->SetScalarRange( Z_MIN, Z_MAX );
127 aMapper->ScalarVisibilityOn();
128 aMapper->SetScalarModeToUsePointData();
129 aMapper->SetLookupTable( aLut );
130 aMapper->SetInputData( aVertexGrid );
132 SALOME_Actor* anActor = SALOME_Actor::New();
133 anActor->SetMapper( aMapper );
134 anActor->setIO( getIO() );
135 AddObject( anActor );