b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | #include <Image_ColorImage.ixx> |
20 | |
21 | #include <Image_ColorPixelDataMap.hxx> |
22 | #include <Image_DataMapIteratorOfColorPixelDataMap.hxx> |
23 | #include <TColStd_Array1OfInteger.hxx> |
24 | #include <Quantity_Array1OfColor.hxx> |
25 | #include <Aspect_ColorMapEntry.hxx> |
26 | |
27 | #ifdef TRACE |
28 | static int Verbose = 0 ; |
29 | #endif |
30 | |
31 | Image_ColorImage::Image_ColorImage ( |
32 | const Standard_Integer x, |
33 | const Standard_Integer y, |
34 | const Standard_Integer dx, |
35 | const Standard_Integer dy) |
36 | : Image_DColorImage( x, y, dx, dy, |
37 | Aspect_ColorPixel( Quantity_Color(0.,0.,0.,Quantity_TOC_RGB)) ) |
38 | |
39 | { |
40 | } |
41 | |
42 | Image_ColorImage::Image_ColorImage ( |
43 | const Standard_Integer x, |
44 | const Standard_Integer y, |
45 | const Standard_Integer dx, |
46 | const Standard_Integer dy, |
47 | const Aspect_ColorPixel& BackPixel ) |
48 | : Image_DColorImage( x, y, dx, dy, BackPixel ) |
49 | |
50 | { |
51 | } |
52 | |
53 | Handle(Image_Image) Image_ColorImage::Dup() const { |
54 | |
55 | Handle(Image_ColorImage) aImage = |
56 | new Image_ColorImage( LowerX(), LowerY(), Width(), Height(), |
57 | BackgroundPixel() ) ; |
58 | |
59 | aImage->InternalDup( this ) ; |
60 | |
61 | return aImage ; |
62 | } |
63 | |
64 | Image_TypeOfImage Image_ColorImage::Type () const { |
65 | |
66 | return Image_TOI_ColorImage ; |
67 | |
68 | } |
69 | |
70 | const Quantity_Color& Image_ColorImage::PixelColor( |
71 | const Standard_Integer x, |
72 | const Standard_Integer y ) const |
73 | |
74 | { return( Pixel( x, y ).Value() ) ; |
75 | } |
76 | |
77 | Handle(Aspect_GenericColorMap) Image_ColorImage::ChooseColorMap( |
78 | const Standard_Integer aSize ) const |
79 | |
80 | { Handle(Aspect_GenericColorMap) TheColorMap = new Aspect_GenericColorMap() ; |
81 | Standard_Integer x,y,i,bblcount, UpX, UpY ; |
82 | Image_ColorPixelDataMap DataMap( 4000 ) ; // a Big DataMap !!! |
83 | Aspect_ColorPixel pix ; |
84 | |
85 | UpX = UpperX() ; |
86 | UpY = UpperY() ; |
87 | |
88 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
89 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
90 | pix = Pixel(x,y) ; |
91 | if ( !DataMap.IsBound( pix ) ) DataMap.Bind( pix, 1 ) ; |
92 | else DataMap( pix )++ ; |
93 | } |
94 | } |
95 | |
96 | #ifdef TRACE |
97 | Standard_Integer CheckSum = 0 ; |
98 | |
99 | if ( Verbose ) |
100 | cout << "ChooseColorMap : Extent " << DataMap.Extent() << endl << flush ; |
101 | #endif |
102 | |
103 | Image_DataMapIteratorOfColorPixelDataMap It( DataMap ) ; |
104 | TColStd_Array1OfInteger Tab( 1, aSize ) ; Tab.Init(0) ; |
105 | Quantity_Array1OfColor Col( 1, aSize) ; Col.Init( |
106 | Quantity_Color( 0.,0.,0., Quantity_TOC_RGB ) ) ; |
107 | Standard_Integer MaxOfTab = 0 ; |
108 | Standard_Integer MinOfTab = 0 ; |
109 | |
110 | while ( It.More() ) { |
111 | bblcount = It.Value() ; |
112 | |
113 | #ifdef TRACE |
114 | if ( Verbose ) { |
115 | cout << CheckSum << "," << It.Key() << "," << bblcount << endl ; |
116 | |
117 | CheckSum += bblcount ; |
118 | } |
119 | #endif |
120 | |
121 | if ( bblcount > MinOfTab ) { |
122 | for ( i = 1 ; i <= aSize ; i++ ) { |
123 | if ( Tab( i ) == MinOfTab ) { |
124 | Tab( i ) = bblcount ; |
125 | Col( i ) = It.Key().Value() ; |
126 | break ; |
127 | } |
128 | } |
129 | |
130 | for ( i = 1 ; i <= aSize ; i++ ) { |
131 | MaxOfTab = Max( MaxOfTab, Tab( i ) ) ; |
132 | MinOfTab = Min( MinOfTab, Tab( i ) ) ; |
133 | } |
134 | |
135 | } |
136 | |
137 | It.Next() ; |
138 | } |
139 | |
140 | Aspect_ColorMapEntry aEntry ; |
141 | |
142 | for ( i = 1, bblcount = 0 ; i <= aSize ; i++ ) { |
143 | if ( Tab( i ) != 0 ) { |
144 | aEntry.SetValue( bblcount++, Col( i ) ) ; |
145 | TheColorMap->AddEntry( aEntry ) ; |
146 | } |
147 | } |
148 | |
149 | cout << flush ; |
150 | |
151 | return TheColorMap ; |
152 | } |
153 | |
154 | #ifdef OLD |
155 | Handle(Standard_Transient) Image_ColorImage::ShallowCopy() const { |
156 | return DeepCopy() ; |
157 | } |
158 | |
159 | Handle(Standard_Transient) Image_ColorImage::DeepCopy() const { |
160 | |
161 | return Dup() ; |
162 | } |
163 | #endif |