1 #include <Image_ColorImage.ixx>
3 #include <Image_ColorPixelDataMap.hxx>
4 #include <Image_DataMapIteratorOfColorPixelDataMap.hxx>
5 #include <TColStd_Array1OfInteger.hxx>
6 #include <Quantity_Array1OfColor.hxx>
7 #include <Aspect_ColorMapEntry.hxx>
10 static int Verbose = 0 ;
13 Image_ColorImage::Image_ColorImage (
14 const Standard_Integer x,
15 const Standard_Integer y,
16 const Standard_Integer dx,
17 const Standard_Integer dy)
18 : Image_DColorImage( x, y, dx, dy,
19 Aspect_ColorPixel( Quantity_Color(0.,0.,0.,Quantity_TOC_RGB)) )
24 Image_ColorImage::Image_ColorImage (
25 const Standard_Integer x,
26 const Standard_Integer y,
27 const Standard_Integer dx,
28 const Standard_Integer dy,
29 const Aspect_ColorPixel& BackPixel )
30 : Image_DColorImage( x, y, dx, dy, BackPixel )
35 Handle(Image_Image) Image_ColorImage::Dup() const {
37 Handle(Image_ColorImage) aImage =
38 new Image_ColorImage( LowerX(), LowerY(), Width(), Height(),
41 aImage->InternalDup( this ) ;
46 Image_TypeOfImage Image_ColorImage::Type () const {
48 return Image_TOI_ColorImage ;
52 const Quantity_Color& Image_ColorImage::PixelColor(
53 const Standard_Integer x,
54 const Standard_Integer y ) const
56 { return( Pixel( x, y ).Value() ) ;
59 Handle(Aspect_GenericColorMap) Image_ColorImage::ChooseColorMap(
60 const Standard_Integer aSize ) const
62 { Handle(Aspect_GenericColorMap) TheColorMap = new Aspect_GenericColorMap() ;
63 Standard_Integer x,y,i,bblcount, UpX, UpY ;
64 Image_ColorPixelDataMap DataMap( 4000 ) ; // a Big DataMap !!!
65 Aspect_ColorPixel pix ;
70 for ( y = LowerY() ; y <= UpY ; y++ ) {
71 for ( x = LowerX() ; x <= UpX ; x++ ) {
73 if ( !DataMap.IsBound( pix ) ) DataMap.Bind( pix, 1 ) ;
74 else DataMap( pix )++ ;
79 Standard_Integer CheckSum = 0 ;
82 cout << "ChooseColorMap : Extent " << DataMap.Extent() << endl << flush ;
85 Image_DataMapIteratorOfColorPixelDataMap It( DataMap ) ;
86 TColStd_Array1OfInteger Tab( 1, aSize ) ; Tab.Init(0) ;
87 Quantity_Array1OfColor Col( 1, aSize) ; Col.Init(
88 Quantity_Color( 0.,0.,0., Quantity_TOC_RGB ) ) ;
89 Standard_Integer MaxOfTab = 0 ;
90 Standard_Integer MinOfTab = 0 ;
93 bblcount = It.Value() ;
97 cout << CheckSum << "," << It.Key() << "," << bblcount << endl ;
99 CheckSum += bblcount ;
103 if ( bblcount > MinOfTab ) {
104 for ( i = 1 ; i <= aSize ; i++ ) {
105 if ( Tab( i ) == MinOfTab ) {
106 Tab( i ) = bblcount ;
107 Col( i ) = It.Key().Value() ;
112 for ( i = 1 ; i <= aSize ; i++ ) {
113 MaxOfTab = Max( MaxOfTab, Tab( i ) ) ;
114 MinOfTab = Min( MinOfTab, Tab( i ) ) ;
122 Aspect_ColorMapEntry aEntry ;
124 for ( i = 1, bblcount = 0 ; i <= aSize ; i++ ) {
125 if ( Tab( i ) != 0 ) {
126 aEntry.SetValue( bblcount++, Col( i ) ) ;
127 TheColorMap->AddEntry( aEntry ) ;
137 Handle(Standard_Transient) Image_ColorImage::ShallowCopy() const {
141 Handle(Standard_Transient) Image_ColorImage::DeepCopy() const {