0025038: Visualization - remove unused classes from package Aspect
[occt.git] / src / Aspect / Aspect_ColorRampColorMap.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // Modified : GG ; 14/09/01 Implements the new AddEntry method
16
17 #define IMP140901       // GG Compute correctly the color ramp
18 //                        accordingly to the requested color.
19
20 #include <Aspect_ColorRampColorMap.ixx>
21 #include <Aspect_ColorMapEntry.hxx>
22 #include <Quantity_NameOfColor.hxx>
23
24
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 )
30
31 { ComputeEntry( basepixel, dimension, 
32                 Quantity_Color( color ) ) ; }
33
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 )
39
40 { ComputeEntry( basepixel, dimension, color ) ; }
41
42 void Aspect_ColorRampColorMap::ComputeEntry( 
43         const Standard_Integer basepixel ,
44         const Standard_Integer dimension ,
45         const Quantity_Color&  color )
46
47 { Standard_Integer i ;
48   Aspect_ColorMapEntry  value ;
49   Quantity_Color         rgb ;
50   Standard_Real  v ;
51 #ifdef IMP140901
52   Standard_Real r,g,b;
53 #endif
54
55         mycolor     = color ;
56         mybasepixel = basepixel ;
57         mydimension = dimension ;
58 #ifdef IMP140901
59         mycolor.Values(r,g,b,Quantity_TOC_RGB);
60 #endif
61
62         for( i = 0 ; i < dimension ; i++ ) {
63                 v = ( Standard_Real ) i / 
64                         ( Standard_Real )(dimension-1) ;
65
66 #ifdef IMP140901
67                 rgb.SetValues( r*v, g*v, b*v, Quantity_TOC_RGB ) ;
68 #else
69                 rgb.SetValues( v, v, v, Quantity_TOC_RGB ) ;
70 #endif
71
72                 value.SetValue( basepixel+i, rgb ) ;
73
74                 mydata.Append( value ) ;
75         }
76 }
77
78 const Aspect_ColorMapEntry& Aspect_ColorRampColorMap::NearestEntry( 
79                                 const Quantity_Color&  color ) const
80
81
82   return( Entry( NearestColorMapIndex( color ) ) ) ;
83 }
84
85 Standard_Integer Aspect_ColorRampColorMap::NearestColorMapIndex( 
86                                 const Quantity_Color&  color ) const
87
88
89 return( (Standard_Integer ) ( ( color.Light() * (mydimension-1) ) + 1 )) ;
90 }
91
92
93 const Aspect_ColorMapEntry& Aspect_ColorRampColorMap::FindEntry( 
94                 const Standard_Integer index ) const 
95
96
97   return( Entry( FindColorMapIndex( index ) ) ) ;
98 }
99
100 Standard_Integer Aspect_ColorRampColorMap::FindColorMapIndex( 
101                 const Standard_Integer index ) const 
102 {
103
104   if (  index < mybasepixel || 
105         index >= ( mybasepixel+mydimension ) ){
106          Aspect_BadAccess::Raise ("FindEntryIndex() index not found.");
107   }
108
109   return( index - mybasepixel + 1 ) ;
110 }
111
112 void Aspect_ColorRampColorMap::ColorRampDefinition( 
113                 Standard_Integer& basepixel,
114                 Standard_Integer& size,
115                 Quantity_Color&   color ) const
116
117 { basepixel = mybasepixel ;
118   size      = mydimension ;
119   color     = mycolor ;
120 }
121
122 Standard_Integer Aspect_ColorRampColorMap::AddEntry (const Quantity_Color &aColor) {
123
124     return mybasepixel + NearestColorMapIndex(aColor) - 1;
125 }
126