1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include <Image_ColorImage.ixx>
#include <Image_ColorPixelDataMap.hxx>
#include <Image_DataMapIteratorOfColorPixelDataMap.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Quantity_Array1OfColor.hxx>
#include <Aspect_ColorMapEntry.hxx>
#ifdef TRACE
static int Verbose = 0 ;
#endif
Image_ColorImage::Image_ColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy)
: Image_DColorImage( x, y, dx, dy,
Aspect_ColorPixel( Quantity_Color(0.,0.,0.,Quantity_TOC_RGB)) )
{
}
Image_ColorImage::Image_ColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy,
const Aspect_ColorPixel& BackPixel )
: Image_DColorImage( x, y, dx, dy, BackPixel )
{
}
Handle(Image_Image) Image_ColorImage::Dup() const {
Handle(Image_ColorImage) aImage =
new Image_ColorImage( LowerX(), LowerY(), Width(), Height(),
BackgroundPixel() ) ;
aImage->InternalDup( this ) ;
return aImage ;
}
Image_TypeOfImage Image_ColorImage::Type () const {
return Image_TOI_ColorImage ;
}
const Quantity_Color& Image_ColorImage::PixelColor(
const Standard_Integer x,
const Standard_Integer y ) const
{ return( Pixel( x, y ).Value() ) ;
}
Handle(Aspect_GenericColorMap) Image_ColorImage::ChooseColorMap(
const Standard_Integer aSize ) const
{ Handle(Aspect_GenericColorMap) TheColorMap = new Aspect_GenericColorMap() ;
Standard_Integer x,y,i,bblcount, UpX, UpY ;
Image_ColorPixelDataMap DataMap( 4000 ) ; // a Big DataMap !!!
Aspect_ColorPixel pix ;
UpX = UpperX() ;
UpY = UpperY() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
pix = Pixel(x,y) ;
if ( !DataMap.IsBound( pix ) ) DataMap.Bind( pix, 1 ) ;
else DataMap( pix )++ ;
}
}
#ifdef TRACE
Standard_Integer CheckSum = 0 ;
if ( Verbose )
cout << "ChooseColorMap : Extent " << DataMap.Extent() << endl << flush ;
#endif
Image_DataMapIteratorOfColorPixelDataMap It( DataMap ) ;
TColStd_Array1OfInteger Tab( 1, aSize ) ; Tab.Init(0) ;
Quantity_Array1OfColor Col( 1, aSize) ; Col.Init(
Quantity_Color( 0.,0.,0., Quantity_TOC_RGB ) ) ;
Standard_Integer MaxOfTab = 0 ;
Standard_Integer MinOfTab = 0 ;
while ( It.More() ) {
bblcount = It.Value() ;
#ifdef TRACE
if ( Verbose ) {
cout << CheckSum << "," << It.Key() << "," << bblcount << endl ;
CheckSum += bblcount ;
}
#endif
if ( bblcount > MinOfTab ) {
for ( i = 1 ; i <= aSize ; i++ ) {
if ( Tab( i ) == MinOfTab ) {
Tab( i ) = bblcount ;
Col( i ) = It.Key().Value() ;
break ;
}
}
for ( i = 1 ; i <= aSize ; i++ ) {
MaxOfTab = Max( MaxOfTab, Tab( i ) ) ;
MinOfTab = Min( MinOfTab, Tab( i ) ) ;
}
}
It.Next() ;
}
Aspect_ColorMapEntry aEntry ;
for ( i = 1, bblcount = 0 ; i <= aSize ; i++ ) {
if ( Tab( i ) != 0 ) {
aEntry.SetValue( bblcount++, Col( i ) ) ;
TheColorMap->AddEntry( aEntry ) ;
}
}
cout << flush ;
return TheColorMap ;
}
#ifdef OLD
Handle(Standard_Transient) Image_ColorImage::ShallowCopy() const {
return DeepCopy() ;
}
Handle(Standard_Transient) Image_ColorImage::DeepCopy() const {
return Dup() ;
}
#endif
|