anatomist  5.1.2
3D neuroimaging data viewer
objectPalette.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANA_COLOR_OBJECTPALETTE_H
36 #define ANA_COLOR_OBJECTPALETTE_H
37 
40 #include <aims/rgb/rgb.h>
42 
43 class QImage;
44 
45 namespace anatomist
46 {
47 
49  {
50  public:
52  {
54  DIAGONAL
55  };
56 
57  typedef AimsRGBA (*MixMethod)(
58  const carto::Volume<AimsRGBA> & map1,
59  const carto::Volume<AimsRGBA> *map2,
60  unsigned x, unsigned y,
61  const AObjectPalette & pal );
62 
65  virtual ~AObjectPalette();
66 
67  virtual AObjectPalette* clone() const;
68 
69  virtual AObjectPalette & operator = ( const AObjectPalette & x );
70 
74  { if( _refPal != pal ) { clearColors(); _refPal = pal; } }
77  { if( !_colors.get() ) const_cast<AObjectPalette *>(this)->fill();
78  return _colors.get(); }
80  { if( !_colors.get() ) fill(); return _colors.get(); }
81  void create( unsigned dimx, unsigned dimy = 1, unsigned dimz = 1,
82  unsigned dimt = 1 );
83  virtual void fill();
84  float min1() const { return( _min ); }
85  float max1() const { return( _max ); }
86  float min2() const { return( _min2 ); }
87  float max2() const { return( _max2 ); }
88  int palette1DMapping() const { return (_palette1DMapping) ; }
89  std::string palette1DMappingName() const
90  { return (_palette1DMapping == 1 ? "Diagonal" : "FirstLine" ) ; }
91  void setMin1( float x )
92  { _min = x; if( isnan( x ) || isinf( x ) ) _min = 0; }
93  void setMax1( float x )
94  { _max = x; if( isnan( x ) || isinf( x ) ) _max = 0; }
95  void setMin2( float x ) { _min2 = x; }
96  void setMax2( float x ) { _max2 = x; }
100  { _palette1DMapping = ( palette1DMappingName == "FirstLine" ?
101  FIRSTLINE : DIAGONAL ) ; }
102  std::string mixMethodName() const { return( _mixMethodName ); }
103  void setMixMethod( const std::string & name );
104  float linearMixFactor() const { return( _linMixFactor ); }
105  void setLinearMixFactor( float x ) { _linMixFactor = x; }
106  bool is2dMode() const { return _mode2d; }
107  void set2dMode( bool x ) { _mode2d = x; }
108  bool isTransparent() const { return _transp; }
109  AimsRGBA normColor( float x, float y = 0 ) const;
110  AimsRGBA normColor( const Point2df & pos ) const;
111  bool zeroCenteredAxis1() const { return _zeroCentered1; }
112  bool zeroCenteredAxis2() const { return _zeroCentered2; }
113  void setZeroCenteredAxis1( bool x ) { _zeroCentered1 = x; }
114  void setZeroCenteredAxis2( bool x ) { _zeroCentered2 = x; }
115 
117  const carto::Volume<AimsRGBA> *map2,
118  unsigned x, unsigned y,
119  const AObjectPalette & pal );
121  const carto::Volume<AimsRGBA> *map2,
122  unsigned x, unsigned y,
123  const AObjectPalette & pal );
125  const carto::Volume<AimsRGBA> *map2,
126  unsigned x, unsigned y,
127  const AObjectPalette & pal );
128  bool set( const carto::GenericObject & );
135  int maxSizeX() const { return _maxSizeX; }
136  int maxSizeY() const { return _maxSizeY; }
137  void setMaxSize( int maxsizex, int maxsizey );
143  int glMaxSizeX() const { return _glMaxSizeX; }
144  int glMaxSizeY() const { return _glMaxSizeY; }
145  void glSetMaxSize( int glmaxsizex, int glmaxsizey );
146  void clearColors();
148  void copyColors( const AObjectPalette & pal );
150  void copyOrFillColors( const AObjectPalette & pal );
151 
152  static std::map<std::string, MixMethod> mixMethods;
153  QImage* toQImage( int w = 0, int h = 0 ) const;
154 
155  protected:
156  static std::map<std::string, MixMethod> defaultMixMethods();
157 
160  float _min;
161  float _max;
163  float _min2;
164  float _max2;
166  std::string _mixMethodName;
169  bool _mode2d;
170  bool _transp;
177  };
178 
179 }
180 
181 
182 #endif
carto::rc_ptr< APalette > _refPal2
bool zeroCenteredAxis2() const
int glMaxSizeX() const
Maximum size of the OpenGL palette image, after scaling.
void create(unsigned dimx, unsigned dimy=1, unsigned dimz=1, unsigned dimt=1)
AObjectPalette(const AObjectPalette &x)
void setMaxSize(int maxsizex, int maxsizey)
void setLinearMixFactor(float x)
bool set(const carto::GenericObject &)
static AimsRGBA linearMixMethod(const carto::Volume< AimsRGBA > &map1, const carto::Volume< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
carto::rc_ptr< APalette > refPalette2() const
Definition: objectPalette.h:72
virtual AObjectPalette * clone() const
Palette1DMapping _palette1DMapping
void setRefPalette2(carto::rc_ptr< APalette > pal)
Definition: objectPalette.h:75
QImage * toQImage(int w=0, int h=0) const
void setZeroCenteredAxis1(bool x)
static std::map< std::string, MixMethod > mixMethods
bool zeroCenteredAxis1() const
carto::rc_ptr< APalette > refPalette() const
Definition: objectPalette.h:71
void setPalette1DMapping(Palette1DMapping palette1DMapping)
Definition: objectPalette.h:97
std::string palette1DMappingName() const
Definition: objectPalette.h:89
void copyColors(const AObjectPalette &pal)
if pal colors size is compatible, just copy it
AObjectPalette(carto::rc_ptr< APalette > pal)
void setPalette1DMappingName(std::string palette1DMappingName)
Definition: objectPalette.h:99
AimsRGBA normColor(float x, float y=0) const
carto::VolumeRef< AimsRGBA > _colors
const carto::Volume< AimsRGBA > * colors() const
Definition: objectPalette.h:76
void glSetMaxSize(int glmaxsizex, int glmaxsizey)
static std::map< std::string, MixMethod > defaultMixMethods()
static AimsRGBA geometricMixMethod(const carto::Volume< AimsRGBA > &map1, const carto::Volume< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
int maxSizeX() const
Maximum size of the internal palette image.
void copyOrFillColors(const AObjectPalette &pal)
if pal colors size is compatible, just copy it; otherwise call fill()
carto::Object genericDescription() const
AimsRGBA normColor(const Point2df &pos) const
float linearMixFactor() const
carto::Volume< AimsRGBA > * colors()
Definition: objectPalette.h:79
AimsRGBA(* MixMethod)(const carto::Volume< AimsRGBA > &map1, const carto::Volume< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
Definition: objectPalette.h:57
std::string mixMethodName() const
void setMixMethod(const std::string &name)
virtual AObjectPalette & operator=(const AObjectPalette &x)
carto::rc_ptr< APalette > _refPal
void setZeroCenteredAxis2(bool x)
static AimsRGBA palette2DMixMethod(const carto::Volume< AimsRGBA > &map1, const carto::Volume< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
void setRefPalette(carto::rc_ptr< APalette > pal)
Definition: objectPalette.h:73