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 HYDROGUI_VTKPrs::compute();
72 if ( !getObject().IsNull() )
74 Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
75 if ( !aBathymetry.IsNull() )
77 HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
78 int aNbPoints = anAltPoints.length();
80 HYDROData_Bathymetry::AltitudePoint anAltPnt;
81 vtkPoints* aPoints = vtkPoints::New();
82 aPoints->SetNumberOfPoints( aNbPoints );
84 vtkPolyData* aVertexGrid = vtkPolyData::New();
85 aVertexGrid->Allocate( aNbPoints );
87 vtkDoubleArray* aZValues = vtkDoubleArray::New();
88 aZValues->Allocate( aNbPoints );
90 vtkVertex* aVertex = vtkVertex::New();
93 int anInvalidZ = InvalidZValue();
94 for (int i = 0; i < aNbPoints; i++ )
96 anAltPnt = anAltPoints.at( i );
98 if ( ValuesLessEquals( aZ, anInvalidZ ) )
100 aZ = Z_MAX; // If Z value is invalid then use Z_MAX
102 aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), aZ );
103 aVertex->GetPointIds()->SetId( 0, i );
104 aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
105 aZValues->InsertNextValue( aZ );
110 aVertexGrid->SetPoints( aPoints );
111 aVertexGrid->GetPointData()->SetScalars( aZValues );
113 // Update the lookup table range if this bathymetry is out of it
116 aZValues->GetRange( myInternalZRange );
117 double* aGlobalRange = myLookupTable->GetRange();
118 // If the global range is not yet initialized or the current one is out of scope then update the global
119 bool anIsUpdated = false;
120 if ( ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) )
122 aGlobalRange[0] = myInternalZRange[0];
126 if ( ValuesEquals( aGlobalRange[1], anInvalidZ ) || ( aGlobalRange[1] < myInternalZRange[1] ) )
128 aGlobalRange[1] = myInternalZRange[1];
134 myLookupTable->SetRange( aGlobalRange );
135 myLookupTable->Build();
138 myMapper->SetScalarRange( aGlobalRange );
139 myMapper->ScalarVisibilityOn();
140 myMapper->SetScalarModeToUsePointData();
141 myMapper->SetLookupTable( myLookupTable );
144 myMapper->SetInputData( aVertexGrid );
146 SALOME_Actor* anActor = getActor<SALOME_Actor>(this);
147 anActor->SetMapper( myMapper.GetPointer() );
148 anActor->setIO( getIO() );
149 AddObject( anActor );
151 aVertexGrid->Delete();