1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 // Modified : GG ; 14/09/01 Implements the new AddEntry method
17 #define IMP140901 // GG Compute correctly the color ramp
18 // accordingly to the requested color.
20 #include <Aspect_ColorRampColorMap.ixx>
21 #include <Aspect_ColorMapEntry.hxx>
22 #include <Quantity_NameOfColor.hxx>
25 Aspect_ColorRampColorMap::Aspect_ColorRampColorMap(
26 const Standard_Integer basepixel ,
27 const Standard_Integer dimension ,
28 const Quantity_NameOfColor color )
29 :Aspect_ColorMap(Aspect_TOC_ColorRamp )
31 { ComputeEntry( basepixel, dimension,
32 Quantity_Color( color ) ) ; }
34 Aspect_ColorRampColorMap::Aspect_ColorRampColorMap(
35 const Standard_Integer basepixel ,
36 const Standard_Integer dimension ,
37 const Quantity_Color& color )
38 :Aspect_ColorMap(Aspect_TOC_ColorRamp )
40 { ComputeEntry( basepixel, dimension, color ) ; }
42 void Aspect_ColorRampColorMap::ComputeEntry(
43 const Standard_Integer basepixel ,
44 const Standard_Integer dimension ,
45 const Quantity_Color& color )
47 { Standard_Integer i ;
48 Aspect_ColorMapEntry value ;
56 mybasepixel = basepixel ;
57 mydimension = dimension ;
59 mycolor.Values(r,g,b,Quantity_TOC_RGB);
62 for( i = 0 ; i < dimension ; i++ ) {
63 v = ( Standard_Real ) i /
64 ( Standard_Real )(dimension-1) ;
67 rgb.SetValues( r*v, g*v, b*v, Quantity_TOC_RGB ) ;
69 rgb.SetValues( v, v, v, Quantity_TOC_RGB ) ;
72 value.SetValue( basepixel+i, rgb ) ;
74 mydata.Append( value ) ;
78 const Aspect_ColorMapEntry& Aspect_ColorRampColorMap::NearestEntry(
79 const Quantity_Color& color ) const
82 return( Entry( NearestColorMapIndex( color ) ) ) ;
85 Standard_Integer Aspect_ColorRampColorMap::NearestColorMapIndex(
86 const Quantity_Color& color ) const
89 return( (Standard_Integer ) ( ( color.Light() * (mydimension-1) ) + 1 )) ;
93 const Aspect_ColorMapEntry& Aspect_ColorRampColorMap::FindEntry(
94 const Standard_Integer index ) const
97 return( Entry( FindColorMapIndex( index ) ) ) ;
100 Standard_Integer Aspect_ColorRampColorMap::FindColorMapIndex(
101 const Standard_Integer index ) const
104 if ( index < mybasepixel ||
105 index >= ( mybasepixel+mydimension ) ){
106 Aspect_BadAccess::Raise ("FindEntryIndex() index not found.");
109 return( index - mybasepixel + 1 ) ;
112 void Aspect_ColorRampColorMap::ColorRampDefinition(
113 Standard_Integer& basepixel,
114 Standard_Integer& size,
115 Quantity_Color& color ) const
117 { basepixel = mybasepixel ;
122 Standard_Integer Aspect_ColorRampColorMap::AddEntry (const Quantity_Color &aColor) {
124 return mybasepixel + NearestColorMapIndex(aColor) - 1;