7fd59977 |
1 | #include <Image_PseudoColorImage.ixx> |
2 | |
3 | #include <Image_LookupTable.hxx> |
4 | #include <TColStd_SetIteratorOfSetOfInteger.hxx> |
5 | #include <TColStd_SetOfInteger.hxx> |
6 | #include <Aspect_GenericColorMap.hxx> |
7 | #include <Aspect_ColorMapEntry.hxx> |
8 | |
9 | Image_PseudoColorImage::Image_PseudoColorImage ( |
10 | const Standard_Integer x, |
11 | const Standard_Integer y, |
12 | const Standard_Integer dx, |
13 | const Standard_Integer dy, |
14 | const Handle(Aspect_ColorMap)& aColorMap) |
15 | : Image_DIndexedImage( x, y, dx, dy, Aspect_IndexPixel( 0 ) ) , |
16 | myColorMap (aColorMap) |
17 | |
18 | { |
19 | } |
20 | |
21 | Image_PseudoColorImage::Image_PseudoColorImage ( |
22 | const Standard_Integer x, |
23 | const Standard_Integer y, |
24 | const Standard_Integer dx, |
25 | const Standard_Integer dy, |
26 | const Handle(Aspect_ColorMap)& aColorMap, |
27 | const Aspect_IndexPixel& Back ) |
28 | : Image_DIndexedImage( x, y, dx, dy, Back ) , myColorMap (aColorMap) |
29 | |
30 | { |
31 | } |
32 | |
33 | Handle(Image_Image) Image_PseudoColorImage::Dup() const { |
34 | |
35 | Handle(Image_PseudoColorImage) aImage = |
36 | new Image_PseudoColorImage( LowerX(), LowerY(), |
37 | Width(), Height(), |
38 | myColorMap, |
39 | BackgroundPixel() ) ; |
40 | |
41 | aImage->InternalDup( this ) ; |
42 | |
43 | return aImage ; |
44 | } |
45 | |
46 | Image_TypeOfImage Image_PseudoColorImage::Type () const { |
47 | |
48 | return Image_TOI_PseudoColorImage ; |
49 | |
50 | } |
51 | |
52 | Handle(Aspect_ColorMap) Image_PseudoColorImage::ColorMap () const { |
53 | |
54 | return myColorMap; |
55 | |
56 | } |
57 | |
58 | const Quantity_Color& Image_PseudoColorImage::PixelColor( |
59 | const Standard_Integer x, |
60 | const Standard_Integer y ) const |
61 | |
62 | { return( myColorMap->FindEntry ( Pixel( x, y ).Value() |
63 | ).Color() ) ; |
64 | } |
65 | |
66 | void Image_PseudoColorImage::RowColor( const Standard_Integer Y, |
67 | Quantity_Array1OfColor& PR) const { |
68 | |
69 | Standard_Integer TheLength = Min (PR.Length(), Width() ); |
70 | Standard_Integer L = PR.Lower() ; |
71 | Standard_Integer X = LowerX() ; |
72 | Standard_Integer NIndex ; |
73 | Standard_Integer PIndex = Pixel( X, Y ).Value() ; |
74 | Quantity_Color PColor = PixelColor( X, Y ) ; |
75 | |
76 | for (Standard_Integer i=0; i< TheLength; i++) { |
77 | NIndex = Pixel(X+i,Y).Value() ; |
78 | if ( NIndex != PIndex ) { |
79 | PIndex = NIndex ; |
80 | PColor = myColorMap->FindEntry( PIndex ).Color() ; |
81 | } |
82 | PR(L+i) = PColor; |
83 | } |
84 | |
85 | } |
86 | |
87 | Handle(Quantity_HArray1OfColor) Image_PseudoColorImage::RowColor( |
88 | const Standard_Integer Y ) const { |
89 | |
90 | Standard_Integer TheLength = Width() ; |
91 | Standard_Integer X = LowerX() ; |
92 | Standard_Integer NIndex ; |
93 | Standard_Integer PIndex = Pixel( X, Y ).Value() ; |
94 | Quantity_Color PColor = PixelColor( X, Y ) ; |
95 | |
96 | Handle(Quantity_HArray1OfColor) PR = |
97 | new Quantity_HArray1OfColor( 0, TheLength-1) ; |
98 | |
99 | for (Standard_Integer i=0; i< TheLength; i++) { |
100 | NIndex = Pixel(X+i,Y).Value() ; |
101 | if ( NIndex != PIndex ) { |
102 | PIndex = NIndex ; |
103 | PColor = myColorMap->FindEntry( PIndex ).Color() ; |
104 | } |
105 | PR->SetValue(i,PColor); |
106 | } |
107 | |
108 | return PR ; |
109 | } |
110 | |
111 | void Image_PseudoColorImage::SqueezedLookupTable( |
112 | const Aspect_IndexPixel& BasePixel, |
113 | Image_LookupTable& aLookup ) const |
114 | |
115 | { TColStd_SetOfInteger PixelSet ; |
116 | TColStd_SetIteratorOfSetOfInteger It; |
117 | Standard_Integer x, y, i, UpX, UpY ; |
118 | // Aspect_IndexPixel aPixel ; |
119 | //Image_LookupTable aLookup( 101 ) ; |
120 | // Aspect_ColorMapEntry aEntry; |
121 | |
122 | UpX = UpperX() ; |
123 | UpY = UpperY() ; |
124 | |
125 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
126 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
127 | PixelSet.Add( Pixel( x, y ).Value() ) ; |
128 | } |
129 | } |
130 | |
131 | #ifdef TRACE |
132 | cout << "Squeeze() PixelSet Extent :" << PixelSet.Extent() << endl ; |
133 | #endif |
134 | |
135 | for (It.Initialize(PixelSet), i = BasePixel.Value() ; |
136 | It.More(); It.Next(), i++ ) { |
137 | aLookup.Bind( It.Value(), i ) ; |
138 | } |
139 | |
140 | // Modif CAL 10/02/95: passage par argument car copie inaccessible. |
141 | // return( aLookup ) ; |
142 | |
143 | } |
144 | |
145 | Handle(Image_PseudoColorImage) Image_PseudoColorImage::Squeeze( |
146 | const Aspect_IndexPixel& BasePixel ) const |
147 | |
148 | { Handle(Image_PseudoColorImage) ret_image = NULL ; |
149 | Handle(Aspect_GenericColorMap) newcmap = NULL ; |
150 | Handle(Aspect_ColorMap) cmap = ColorMap() ; |
151 | TColStd_SetOfInteger PixelSet ; |
152 | TColStd_SetIteratorOfSetOfInteger It; |
153 | Standard_Integer x, y, i, UpX, UpY ; |
154 | // Aspect_IndexPixel aPixel ; |
155 | Image_LookupTable aLookup( 101 ) ; |
156 | Aspect_ColorMapEntry aEntry; |
157 | |
158 | UpX = UpperX() ; |
159 | UpY = UpperY() ; |
160 | |
161 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
162 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
163 | PixelSet.Add( Pixel( x, y ).Value() ) ; |
164 | } |
165 | } |
166 | |
167 | #ifdef TRACE |
168 | cout << "Squeeze() PixelSet Extent :" << PixelSet.Extent() << endl ; |
169 | #endif |
170 | |
171 | if ( PixelSet.Extent() != 0 ) { |
172 | newcmap = new Aspect_GenericColorMap() ; |
173 | |
174 | for (It.Initialize(PixelSet), i = BasePixel.Value() ; |
175 | It.More(); It.Next(), i++ ) { |
176 | aLookup.Bind( It.Value(), i ) ; |
177 | aEntry.SetValue( i, cmap->FindEntry( It.Value() ).Color() ) ; |
178 | newcmap->AddEntry( aEntry ) ; |
179 | } |
180 | |
181 | ret_image = new Image_PseudoColorImage( LowerX(), LowerY(), |
182 | Width() , Height(), |
183 | newcmap ); |
184 | |
185 | ret_image->Fill( this ) ; |
186 | |
187 | ret_image->Lookup( aLookup ) ; |
188 | |
189 | } |
190 | |
191 | return( ret_image ) ; |
192 | |
193 | } |
194 | |
195 | void Image_PseudoColorImage::Lookup( const Image_LookupTable& aLookup ) |
196 | |
197 | { Standard_Integer x,y, UpX, UpY; |
198 | Aspect_IndexPixel val, lastval, newval; |
199 | |
200 | UpX = UpperX() ; |
201 | UpY = UpperY() ; |
202 | |
203 | val = Pixel( LowerX(), LowerY() ) ; |
204 | lastval = val ; |
205 | newval = aLookup.Find( lastval ) ; |
206 | |
207 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
208 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
209 | val = Pixel( x, y ) ; |
210 | if ( !(val == lastval) ) { |
211 | lastval = val ; |
212 | newval = aLookup.Find( lastval ) ; |
213 | } |
214 | SetPixel( x, y , newval ) ; |
215 | } |
216 | } |
217 | |
218 | } |
219 | |
220 | void Image_PseudoColorImage::Rescale( const Standard_Real Scale, |
221 | const Standard_Real Offset ) |
222 | |
223 | { Standard_Real S = Scale ; |
224 | Standard_Real O = Offset ; |
225 | Standard_Integer x,y, UpX, UpY, val; |
226 | |
227 | UpX = UpperX() ; |
228 | UpY = UpperY() ; |
229 | |
230 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
231 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
232 | val = ( Standard_Integer ) ( Pixel(x, y).Value() * S + O ) ; |
233 | MutPixel( x, y ).SetValue( val ) ; |
234 | } |
235 | } |
236 | |
237 | } |
238 | |
239 | void Image_PseudoColorImage::Extrema( Aspect_IndexPixel& PMin, |
240 | Aspect_IndexPixel& PMax ) const |
241 | |
242 | { Standard_Integer x,y, UpX, UpY, min, max, val, lastval; |
243 | // Aspect_IndexPixel aPixel ; |
244 | |
245 | UpX = UpperX() ; |
246 | UpY = UpperY() ; |
247 | |
248 | max = IntegerFirst() ; |
249 | min = IntegerLast() ; |
250 | |
251 | lastval = Pixel( LowerX(), LowerY() ).Value() ; |
252 | |
253 | max = Max( max, lastval ) ; |
254 | min = Min( min, lastval ) ; |
255 | |
256 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
257 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
258 | val = Pixel( x, y ).Value(); |
259 | if ( val != lastval ) { |
260 | lastval = val ; |
261 | max = Max( max, lastval ) ; |
262 | min = Min( min, lastval ) ; |
263 | } |
264 | } |
265 | } |
266 | |
267 | PMin.SetValue( min ) ; |
268 | PMax.SetValue( max ) ; |
269 | |
270 | } |
271 | |
272 | void Image_PseudoColorImage::Threshold( const Aspect_IndexPixel& PMin, |
273 | const Aspect_IndexPixel& PMax, |
274 | const Aspect_IndexPixel& PMap ) |
275 | |
276 | { Standard_Integer x,y, UpX, UpY, min, max, val, map ; |
277 | Aspect_IndexPixel ThePixel ; |
278 | UpX = UpperX() ; |
279 | UpY = UpperY() ; |
280 | |
281 | max = PMax.Value() ; |
282 | min = PMin.Value() ; |
283 | map = PMap.Value() ; |
284 | |
285 | for ( y = LowerY() ; y <= UpY ; y++ ) { |
286 | for ( x = LowerX() ; x <= UpX ; x++ ) { |
287 | ThePixel = Pixel( x, y ) ; |
288 | val = Pixel( x, y ).Value(); |
289 | if ( val >= min && val <= max ) { |
290 | MutPixel( x, y ).SetValue( map ) ; |
291 | } |
292 | } |
293 | } |
294 | } |
295 | #ifdef OLD |
296 | Handle(Standard_Transient) Image_PseudoColorImage::ShallowCopy() const { |
297 | return DeepCopy() ; |
298 | } |
299 | |
300 | Handle(Standard_Transient) Image_PseudoColorImage::DeepCopy() const { |
301 | |
302 | return Dup() ; |
303 | } |
304 | #endif |