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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
|
#ifndef DISPLAYMAPPINGPOLICY_H
#define DISPLAYMAPPINGPOLICY_H
#include "ImageWrapperBase.h"
#include "itkDataObject.h"
#include "itkObjectFactory.h"
#include "IntensityToColorLookupTableImageFilter.h"
class ColorLabelTable;
class LabelToRGBAFilter;
class IntensityCurveVTK;
class Registry;
template <class TEnum> class RegistryEnumMap;
template <class T, class U> class LookupTableIntensityMappingFilter;
template <class T> class RGBALookupTableIntensityMappingFilter;
template <class T, typename U> class InputSelectionImageFilter;
/**
* @brief An abstract class describing intensity mapping between image
* intensities stored internally in an itk image and RGBA intensities
* displayed to the user. This class is a parent in a hierarchy of
* policies used to customize ImageWrapper behavior.
*/
class AbstractDisplayMappingPolicy : public itk::DataObject
{
public:
irisITKAbstractObjectMacro(AbstractDisplayMappingPolicy, itk::DataObject)
typedef ImageWrapperBase::DisplaySliceType DisplaySliceType;
typedef ImageWrapperBase::DisplaySlicePointer DisplaySlicePointer;
virtual IntensityCurveInterface *GetIntensityCurve() const = 0;
virtual ColorMap *GetColorMap() const = 0;
virtual DisplaySlicePointer GetDisplaySlice(unsigned int slice) = 0;
virtual void Save(Registry &folder) = 0;
virtual void Restore(Registry &folder) = 0;
};
class AbstractColorLabelTableDisplayMappingPolicy : public AbstractDisplayMappingPolicy
{
public:
irisITKAbstractObjectMacro(AbstractColorLabelTableDisplayMappingPolicy,
AbstractDisplayMappingPolicy)
/**
* Set the table of color labels used to produce color slice images
*/
virtual void SetLabelColorTable(ColorLabelTable *labels) = 0;
/**
* Get the color label table
*/
virtual ColorLabelTable *GetLabelColorTable() const = 0;
};
template <class TWrapperTraits>
class ColorLabelTableDisplayMappingPolicy
: public AbstractColorLabelTableDisplayMappingPolicy
{
public:
irisITKObjectMacro(ColorLabelTableDisplayMappingPolicy<TWrapperTraits>,
AbstractColorLabelTableDisplayMappingPolicy)
typedef typename TWrapperTraits::WrapperType WrapperType;
typedef typename TWrapperTraits::ImageType ImageType;
typedef itk::Image<LabelType, 2> InputSliceType;
typedef ImageWrapperBase::DisplaySliceType DisplaySliceType;
typedef ImageWrapperBase::DisplaySlicePointer DisplaySlicePointer;
typedef InputSliceType::PixelType InputPixelType;
typedef DisplaySliceType::PixelType DisplayPixelType;
/**
* Set the table of color labels used to produce color slice images
*/
void SetLabelColorTable(ColorLabelTable *labels);
/**
* Get the color label table
*/
ColorLabelTable *GetLabelColorTable() const;
void Initialize(WrapperType *wrapper);
void UpdateImagePointer(ImageType *image);
DisplaySlicePointer GetDisplaySlice(unsigned int slice);
virtual IntensityCurveInterface *GetIntensityCurve() const { return NULL; }
virtual ColorMap *GetColorMap() const { return NULL; }
virtual void Save(Registry &folder) {}
virtual void Restore(Registry &folder) {}
virtual DisplayPixelType MapPixel(const InputPixelType &val);
protected:
ColorLabelTableDisplayMappingPolicy();
~ColorLabelTableDisplayMappingPolicy();
typedef LabelToRGBAFilter RGBAFilterType;
typedef SmartPtr<RGBAFilterType> RGBAFilterPointer;
RGBAFilterPointer m_RGBAFilter[3];
WrapperType *m_Wrapper;
};
/**
* @brief The parent class for the policies that involve curve-based mappings,
* for both scalar and vector images.
*/
class AbstractContinuousImageDisplayMappingPolicy : public AbstractDisplayMappingPolicy
{
public:
irisITKAbstractObjectMacro(AbstractContinuousImageDisplayMappingPolicy,
AbstractDisplayMappingPolicy)
virtual IntensityCurveInterface *GetIntensityCurve() const = 0;
/**
* @brief Get the intensity range relative to which the contrast mapping
* curve is constructed. This is primarily used when displaying the curve
* to the user.
* @return Vector containing min/max of the curve range (in native units)
*/
virtual Vector2d GetNativeImageRangeForCurve() = 0;
/**
* @brief Get the histogram associated with the current state of the display
* policy. For single-component layers, this method just returns the
* component's histogram. For multi-component layers, it may return the
* pooled histogram, e.g., when the display is in RGB mode
* @param nBins Number of bins desired in the histogram
*/
virtual const ScalarImageHistogram *GetHistogram(int nBins) = 0;
virtual void SetColorMap(ColorMap *map) = 0;
/**
* Automatically fit the contrast mapping based on the percentiles of
* the image histogram.
* TODO: the accuracy of this is currently limited by the bin size in
* the histogram. At some point, it may make sense to have separate
* histograms for display and for auto-fitting.
*/
virtual void AutoFitContrast();
/**
* Has the intensity curve been adjusted from its default (reset) state?
*/
virtual bool IsContrastInDefaultState();
};
class AbstractCachingAndColorMapDisplayMappingPolicy
: public AbstractContinuousImageDisplayMappingPolicy
{
public:
irisITKAbstractObjectMacro(AbstractCachingAndColorMapDisplayMappingPolicy,
AbstractContinuousImageDisplayMappingPolicy)
};
template<class TWrapperTraits>
class CachingCurveAndColorMapDisplayMappingPolicy
: public AbstractCachingAndColorMapDisplayMappingPolicy
{
public:
irisITKObjectMacro(CachingCurveAndColorMapDisplayMappingPolicy<TWrapperTraits>,
AbstractCachingAndColorMapDisplayMappingPolicy)
typedef typename TWrapperTraits::WrapperType WrapperType;
typedef typename TWrapperTraits::ImageType ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename TWrapperTraits::ComponentType ComponentType;
typedef itk::Image<PixelType, 2> InputSliceType;
typedef ImageWrapperBase::DisplaySliceType DisplaySliceType;
typedef ImageWrapperBase::DisplaySlicePointer DisplaySlicePointer;
typedef ImageWrapperBase::DisplayPixelType DisplayPixelType;
// Lookup table
typedef itk::Image<DisplayPixelType, 1> LookupTableType;
// Min/Max inputs
typedef itk::SimpleDataObjectDecorator<ComponentType> ComponentObjectType;
/**
* @brief Copy the LUT, intensity curve, and color map from another display
* mapping. This allows memory savings by sharing the LUT among multiple
* wrappers. This is used with components on a multi-component image
*/
void CopyDisplayPipeline(const Self *reference);
void DeepCopyIntensityMap(WrapperType *srcWrapper);
/**
* Set the reference intensity range for the lookup table and intensity curve.
* This means that the LUT is constructed not between the image min and image
* max, but between some other pair of values. This is useful when the image
* in the imagewrapper is a subregion of another image, or when the image is
* a component of a multi-component image.
*/
void SetReferenceIntensityRange(ComponentObjectType *refMin,
ComponentObjectType *refMax);
void ClearReferenceIntensityRange();
Vector2d GetNativeImageRangeForCurve();
virtual const ScalarImageHistogram *GetHistogram(int nBins);
/**
* Get the display slice in a given direction. To change the
* display slice, call parent's MoveToSlice() method
*/
DisplaySlicePointer GetDisplaySlice(unsigned int dim);
/**
Get a pointer to the colormap
*/
ColorMap *GetColorMap () const;
void SetColorMap(ColorMap *map);
/**
* Get a pointer to the intensity curve
*/
virtual IntensityCurveInterface *GetIntensityCurve() const;
/**
* Set a new intensity curve
*/
void SetIntensityCurve(IntensityCurveInterface *curve);
void Initialize(WrapperType *wrapper);
void UpdateImagePointer(ImageType *image);
virtual void Save(Registry &folder);
virtual void Restore(Registry &folder);
virtual DisplayPixelType MapPixel(const PixelType &val);
protected:
CachingCurveAndColorMapDisplayMappingPolicy();
~CachingCurveAndColorMapDisplayMappingPolicy();
// Filter that generates the lookup table
typedef IntensityToColorLookupTableImageFilter<
ImageType, LookupTableType> LookupTableFilterType;
// Filter that applies the lookup table to slices
typedef LookupTableIntensityMappingFilter<
InputSliceType, DisplaySliceType> IntensityFilterType;
// LUT generator
SmartPtr<LookupTableFilterType> m_LookupTableFilter;
// Filters for the three slice directions
SmartPtr<IntensityFilterType> m_IntensityFilter[3];
/**
* Implementation of the intensity curve funcitonality. The intensity map
* transforms input intensity values into the range [0 1], which serves as
* the input into the color map transform.
*/
SmartPtr<IntensityCurveVTK> m_IntensityCurveVTK;
/**
* Color map, which maps intensity values normalized to the range [0 1]
* to output RGB values
*/
SmartPtr<ColorMap> m_ColorMap;
WrapperType *m_Wrapper;
};
/*
template<class TWrapperTraits>
class SpeedImageWrapperDisplayPolicy
: public LinearColorMapDisplayMappingPolicy
{
public:
irisITKObjectMacro(SpeedImageWrapperDisplayPolicy<TWrapperTraits>,
CachingCurveAndColorMapDisplayMappingPolicy<TWrapperTraits>)
void UpdateImagePointer(ImageType *image);
protected:
SpeedImageWrapperDisplayPolicy() {}
virtual ~SpeedImageWrapperDisplayPolicy() {}
};
*/
/**
* This little struct describes the behavior of the multichannel display
* mapping policy
*/
struct MultiChannelDisplayMode
{
/**
* Whether or not components are mapped to RGB channels. This is only
* allowed if the image has 3 components
*/
bool UseRGB;
/**
* Special mode for rendering 3-component images as displacement grids
*/
bool RenderAsGrid;
/**
* When not in RGB mode, which scalar representation is selected for
* display. Only used if UseRGB is false.
*/
ScalarRepresentation SelectedScalarRep;
/**
* When the scalar representation is 'component', which component is
* selected for display.
*/
int SelectedComponent;
/** Default constructor - select first component */
MultiChannelDisplayMode();
/** Default constructor - select first component */
MultiChannelDisplayMode(bool use_rgb, bool render_as_grid,
ScalarRepresentation rep,
int comp = 0);
/** Constructor from an integer, used for compatibility purposes, allowing
* zero to be cast to the default mode state */
MultiChannelDisplayMode(int value);
/** Initialize for RGB mode */
static MultiChannelDisplayMode DefaultForRGB();
/** Save to registry */
void Save(Registry ®);
/** Restore from registry */
static MultiChannelDisplayMode Load(Registry ®);
static RegistryEnumMap<ScalarRepresentation> &GetScalarRepNames();
/** Get a hash value for this struct - for ordering purposes */
int GetHashValue() const;
/**
* Whether the mode is a single-component mode: i.e., non-RGB and the
* ScalarRepresentation is single component
*/
bool IsSingleComponent();
/** Comparison operators */
bool operator == (const MultiChannelDisplayMode &mode) const
{ return GetHashValue() == mode.GetHashValue(); }
bool operator != (const MultiChannelDisplayMode &mode) const
{ return GetHashValue() != mode.GetHashValue(); }
};
bool operator < (const MultiChannelDisplayMode &a, const MultiChannelDisplayMode &b);
/**
* Display mapping policy for speed and level set images, i.e., images that
* have a defined range of intensity and a colormap that takes them from
* intensity values to display RGB values. This policy can work with both
* integral and floating point types.
*/
class AbstractLinearColorMapDisplayMappingPolicy : public AbstractDisplayMappingPolicy
{
public:
irisITKAbstractObjectMacro(AbstractLinearColorMapDisplayMappingPolicy,
AbstractContinuousImageDisplayMappingPolicy)
};
namespace itk {
template <class TInput,class TOutput,class TFunctor>
class UnaryFunctorImageFilter;
}
template <class TWrapperTraits>
class LinearColorMapDisplayMappingPolicy
: public AbstractLinearColorMapDisplayMappingPolicy
{
public:
irisITKObjectMacro(LinearColorMapDisplayMappingPolicy<TWrapperTraits>,
AbstractLinearColorMapDisplayMappingPolicy)
typedef typename TWrapperTraits::WrapperType WrapperType;
typedef typename TWrapperTraits::ImageType ImageType;
typedef typename ImageType::PixelType PixelType;
typedef itk::Image<PixelType, 2> InputSliceType;
typedef ImageWrapperBase::DisplaySliceType DisplaySliceType;
typedef ImageWrapperBase::DisplaySlicePointer DisplaySlicePointer;
typedef ImageWrapperBase::DisplayPixelType DisplayPixelType;
void Initialize(WrapperType *wrapper);
void UpdateImagePointer(ImageType *image);
virtual DisplaySlicePointer GetDisplaySlice(unsigned int slice);
virtual IntensityCurveInterface *GetIntensityCurve() const { return NULL; }
virtual void Save(Registry &folder);
virtual void Restore(Registry &folder);
irisGetMacro(ColorMap, ColorMap *)
DisplayPixelType MapPixel(const PixelType &xin);
protected:
LinearColorMapDisplayMappingPolicy();
virtual ~LinearColorMapDisplayMappingPolicy();
class MappingFunctor
{
public:
DisplayPixelType operator()(PixelType in);
double m_Scale, m_Shift;
ColorMap *m_ColorMap;
bool operator != (const MappingFunctor &f);
};
typedef itk::UnaryFunctorImageFilter
<InputSliceType, DisplaySliceType, MappingFunctor> IntensityFilterType;
typedef SmartPtr<IntensityFilterType> IntensityFilterPointer;
IntensityFilterPointer m_Filter[3];
MappingFunctor m_Functor;
SmartPtr<ColorMap> m_ColorMap;
WrapperType *m_Wrapper;
};
class AbstractMultiChannelDisplayMappingPolicy
: public AbstractContinuousImageDisplayMappingPolicy
{
public:
irisITKAbstractObjectMacro(AbstractMultiChannelDisplayMappingPolicy,
AbstractContinuousImageDisplayMappingPolicy)
irisVirtualGetMacro(DisplayMode, MultiChannelDisplayMode)
irisVirtualSetMacro(DisplayMode, MultiChannelDisplayMode)
irisVirtualGetMacro(Animate, bool)
irisVirtualSetMacro(Animate, bool)
};
template <class TWrapperTraits>
class MultiChannelDisplayMappingPolicy
: public AbstractMultiChannelDisplayMappingPolicy
{
public:
irisITKObjectMacro(MultiChannelDisplayMappingPolicy<TWrapperTraits>,
AbstractMultiChannelDisplayMappingPolicy)
typedef typename TWrapperTraits::WrapperType WrapperType;
typedef typename TWrapperTraits::ImageType ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename ImageType::InternalPixelType InternalPixelType;
typedef itk::Image<InternalPixelType, 2> InputSliceType;
typedef ImageWrapperBase::DisplaySliceType DisplaySliceType;
typedef ImageWrapperBase::DisplaySlicePointer DisplaySlicePointer;
typedef ImageWrapperBase::DisplayPixelType DisplayPixelType;
void Initialize(WrapperType *wrapper);
void UpdateImagePointer(ImageType *image);
/** Set the display mode */
virtual void SetDisplayMode(MultiChannelDisplayMode mode);
/** Get the display mode */
irisGetMacro(DisplayMode, MultiChannelDisplayMode)
/** Get/Set the animation status */
irisGetSetMacro(Animate, bool)
DisplaySlicePointer GetDisplaySlice(unsigned int slice);
Vector2d GetNativeImageRangeForCurve();
virtual const ScalarImageHistogram *GetHistogram(int nBins);
/**
* @brief Returns true when the display mode is such that the image min, max
* and histogram used for contrast adjustment purposes use intensities pooled
* from all of the components. This is the case when the components are being
* animated or when display is in RGB mode.
*/
bool IsContrastMultiComponent() const;
virtual IntensityCurveInterface *GetIntensityCurve() const;
virtual ColorMap *GetColorMap() const;
virtual void SetColorMap(ColorMap *map);
virtual void Save(Registry &folder);
virtual void Restore(Registry &folder);
virtual void AutoFitContrast();
irisGetMacro(ScalarRepresentation, ScalarImageWrapperBase *)
DisplayPixelType MapPixel(const PixelType &val);
protected:
MultiChannelDisplayMappingPolicy();
~MultiChannelDisplayMappingPolicy();
typedef RGBALookupTableIntensityMappingFilter<InputSliceType> ApplyLUTFilter;
typedef itk::Image<unsigned char, 1> LookupTableType;
typedef MultiComponentImageToScalarLookupTableImageFilter<ImageType, LookupTableType>
GenerateLUTFilter;
MultiChannelDisplayMode m_DisplayMode;
bool m_Animate;
ScalarImageWrapperBase *m_ScalarRepresentation;
WrapperType *m_Wrapper;
SmartPtr<GenerateLUTFilter> m_LUTGenerator;
SmartPtr<ApplyLUTFilter> m_RGBMapper[3];
// Filters used to select the right pipeline for display
typedef InputSelectionImageFilter<
DisplaySliceType, MultiChannelDisplayMode> DisplaySliceSelector;
SmartPtr<DisplaySliceSelector> m_DisplaySliceSelector[3];
};
#endif // DISPLAYMAPPINGPOLICY_H
|