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 #include <Aspect_ColorCubeColorMap.ixx>
18 #include <Aspect_ColorMapEntry.hxx>
21 static int Tlevel = 0 ;
24 Aspect_ColorCubeColorMap::Aspect_ColorCubeColorMap(
25 const Standard_Integer basepixel ,
26 const Standard_Integer red_max ,
27 const Standard_Integer red_mult ,
28 const Standard_Integer green_max ,
29 const Standard_Integer green_mult ,
30 const Standard_Integer blue_max ,
31 const Standard_Integer blue_mult )
32 :Aspect_ColorMap( Aspect_TOC_ColorCube )
34 { Standard_Integer r,g,b,i ;
35 Aspect_ColorMapEntry value ;
37 Standard_Integer max[3], mult[3], ti[3];
39 mybasepixel = basepixel ;
41 myredmult = red_mult ;
42 mygreenmax = green_max ;
43 mygreenmult = green_mult ;
44 mybluemax = blue_max ;
45 mybluemult = blue_mult ;
47 r = 0 ; g = 1 ; b = 2 ;
49 if ( ( myredmult < mygreenmult ) && ( myredmult < mybluemult ) ) {
51 if ( mygreenmult < mybluemult ) { g = 1 ; b = 2 ; }
52 else { b = 1 ; g = 2 ; }
54 if ( ( mygreenmult < myredmult ) && ( mygreenmult < mybluemult ) ) {
56 if ( myredmult < mybluemult ) { r = 1 ; b = 2 ; }
57 else { b = 1 ; r = 2 ; }
59 if ( ( mybluemult < myredmult ) && ( mybluemult < mygreenmult ) ) {
61 if ( myredmult < mygreenmult ) { r = 1 ; g = 2 ; }
62 else { g = 1 ; r = 2 ; }
67 cout << "ColorCubeColorMap constructor (r,g,b) :"
68 << r << "," << g << "," << b << endl << flush ;
71 mult[r] = myredmult ; max[r] = myredmax ;
72 mult[g] = mygreenmult ; max[g] = mygreenmax ;
73 mult[b] = mybluemult ; max[b] = mybluemax ;
75 for( ti[2] = 0 ; ti[2] <= max[2] ; ti[2]++ ) {
76 for( ti[1] = 0 ; ti[1] <= max[1] ; ti[1]++ ) {
77 for( ti[0] = 0 ; ti[0] <= max[0] ; ti[0]++ ) {
78 rgb.SetValues( (Standard_Real) ti[r] / (Standard_Real) max[r],
79 (Standard_Real) ti[g] / (Standard_Real) max[g],
80 (Standard_Real) ti[b] / (Standard_Real) max[b],
83 i = ti[r] * mult[r] + ti[g] * mult[g] + ti[b] * mult[b] ;
85 value.SetValue( mybasepixel+i, rgb ) ;
90 mydata.Append( value ) ;
96 const Aspect_ColorMapEntry& Aspect_ColorCubeColorMap::NearestEntry(
97 const Quantity_Color& color ) const
100 return( Entry( NearestColorMapIndex( color ) ) ) ;
103 Standard_Integer Aspect_ColorCubeColorMap::NearestColorMapIndex(
104 const Quantity_Color& color ) const
106 { Standard_Integer r,g,b ;
108 r = (Standard_Integer ) ( color.Red() * myredmax + 0.5) ;
109 g = (Standard_Integer ) ( color.Green() * mygreenmax + 0.5) ;
110 b = (Standard_Integer ) ( color.Blue() * mybluemax + 0.5) ;
112 return( r*myredmult+g*mygreenmult+b*mybluemult + 1 ) ;
115 const Aspect_ColorMapEntry& Aspect_ColorCubeColorMap::FindEntry(
116 const Standard_Integer index ) const
119 return( Entry( FindColorMapIndex( index ) ) ) ;
122 Standard_Integer Aspect_ColorCubeColorMap::FindColorMapIndex(
123 const Standard_Integer index ) const
126 if ( index < mybasepixel ||
127 index >= ( mybasepixel+Size() ) ){
128 Aspect_BadAccess::Raise ("FindEntryIndex() index not found.");
131 return( index - mybasepixel + 1 ) ;
134 void Aspect_ColorCubeColorMap::ColorCubeDefinition(
135 Standard_Integer& basepixel ,
136 Standard_Integer& red_max ,
137 Standard_Integer& red_mult ,
138 Standard_Integer& green_max ,
139 Standard_Integer& green_mult ,
140 Standard_Integer& blue_max ,
141 Standard_Integer& blue_mult ) const
144 basepixel = mybasepixel ;
146 red_mult = myredmult ;
147 green_max = mygreenmax ;
148 green_mult = mygreenmult ;
149 blue_max = mybluemax ;
150 blue_mult = mybluemult ;
153 Standard_Integer Aspect_ColorCubeColorMap::AddEntry (const Quantity_Color &aColor) {
155 return mybasepixel + NearestColorMapIndex(aColor) - 1;