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>
37 #include <vtkLookupTable.h>
42 \brief Maximum Z value used in bathymetry presentation.
44 This value is used instead of invalid values.
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 = InvalidZValue();
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 // Update the lookup table range if this bathymetry is out of it
119 double* aRange = aZValues->GetRange();
120 myInternalZRange[0] = -aRange[1];
121 myInternalZRange[1] = -aRange[0];
123 double* aGlobalRange = myLookupTable->GetRange();
124 // If the global range is not yet initialized or the current one is out of scope then update the global
125 bool anIsUpdated = false;
126 if ( ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) )
128 aGlobalRange[0] = myInternalZRange[0];
132 if ( ValuesEquals( aGlobalRange[1], anInvalidZ ) || ( aGlobalRange[1] < myInternalZRange[1] ) )
134 aGlobalRange[1] = myInternalZRange[1];
140 myLookupTable->SetRange( aGlobalRange );
141 myLookupTable->Build();
144 myMapper->SetScalarRange( -aGlobalRange[1], -aGlobalRange[0] );
145 myMapper->ScalarVisibilityOn();
146 myMapper->SetScalarModeToUsePointData();
149 vtkLookupTable* aTable = vtkLookupTable::New();
150 vtkLookupTable* aGlobalTable = vtkLookupTable::SafeDownCast( myLookupTable );
151 double* aHueRange = aGlobalTable->GetHueRange();
152 // Revert hue range to keep it the same as for appropriate positive Z values in scalar bar
153 aTable->SetHueRange( aHueRange[1], aHueRange[0] );
154 aTable->SetSaturationRange( aGlobalTable->GetSaturationRange() );
155 // Revert the Z values range from positive to negative to show them as depth
156 aTable->SetTableRange( -aGlobalRange[1], -aGlobalRange[0] );
157 aTable->SetValueRange( aGlobalTable->GetValueRange() );
158 aTable->SetAlphaRange( aGlobalTable->GetAlphaRange() );
159 aTable->SetNumberOfColors( aGlobalTable->GetNumberOfColors() );
162 myMapper->SetLookupTable( aTable );
164 // myMapper->SetLookupTable( myLookupTable );
167 myMapper->SetInputData( aVertexGrid );
169 SALOME_Actor* anActor = SALOME_Actor::New();
170 anActor->SetMapper( myMapper.GetPointer() );
171 anActor->setIO( getIO() );
172 AddObject( anActor );
175 aVertexGrid->Delete();