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 <vtkScalarBarActor.h>
41 \brief Maximum Z value used in bathymetry presentation.
43 This value is used instead of invalid values.
47 //=======================================================================
48 // name : HYDROGUI_VTKPrsBathymetry
49 // Purpose : Constructor
50 //=======================================================================
51 HYDROGUI_VTKPrsBathymetry::HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject )
52 : HYDROGUI_VTKPrs( theObject )
56 //=======================================================================
57 // name : HYDROGUI_VTKPrsBathymetry
58 // Purpose : Destructor
59 //=======================================================================
60 HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry()
64 //================================================================
67 //================================================================
68 void HYDROGUI_VTKPrsBathymetry::compute()
70 if ( !getObject().IsNull() )
72 Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
73 if ( !aBathymetry.IsNull() )
75 HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
76 int aNbPoints = anAltPoints.length();
78 HYDROData_Bathymetry::AltitudePoint anAltPnt;
79 vtkPoints* aPoints = vtkPoints::New();
80 aPoints->SetNumberOfPoints( aNbPoints );
82 vtkPolyData* aVertexGrid = vtkPolyData::New();
83 aVertexGrid->Allocate( aNbPoints );
85 vtkDoubleArray* aZValues = vtkDoubleArray::New();
86 aZValues->Allocate( aNbPoints );
88 vtkVertex* aVertex = vtkVertex::New();
91 int anInvalidZ = InvalidZValue();
92 for (int i = 0; i < aNbPoints; i++ )
94 anAltPnt = anAltPoints.at( i );
96 if ( ValuesLessEquals( aZ, anInvalidZ ) )
104 aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), aZ );
105 aVertex->GetPointIds()->SetId( 0, i );
106 aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
107 aZValues->InsertNextValue( aZ );
112 aVertexGrid->SetPoints( aPoints );
113 aVertexGrid->GetPointData()->SetScalars( aZValues );
115 // Update the lookup table range if this bathymetry is out of it
118 aZValues->GetRange( myInternalZRange );
119 double* aGlobalRange = myLookupTable->GetRange();
120 // If the global range is not yet initialized or the current one is out of scope then update the global
121 bool anIsUpdated = false;
122 if ( ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) )
124 aGlobalRange[0] = myInternalZRange[0];
128 if ( ValuesEquals( aGlobalRange[1], anInvalidZ ) || ( aGlobalRange[1] < myInternalZRange[1] ) )
130 aGlobalRange[1] = myInternalZRange[1];
136 myLookupTable->SetRange( aGlobalRange );
137 myLookupTable->Build();
140 myMapper->SetScalarRange( aGlobalRange );
141 myMapper->ScalarVisibilityOn();
142 myMapper->SetScalarModeToUsePointData();
143 myMapper->SetLookupTable( myLookupTable );
146 myMapper->SetInputData( aVertexGrid );
148 SALOME_Actor* anActor = SALOME_Actor::New();
149 anActor->SetMapper( myMapper.GetPointer() );
150 anActor->setIO( getIO() );
151 AddObject( anActor );
154 aVertexGrid->Delete();