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
|
/*=========================================================================
Program: ITK-SNAP
Module: $RCSfile: IRISSlicer.h,v $
Language: C++
Date: $Date: 2007/12/30 04:05:15 $
Version: $Revision: 1.3 $
Copyright (c) 2007 Paul A. Yushkevich
This file is part of ITK-SNAP
ITK-SNAP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-----
Copyright (c) 2003 Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __IRISSlicer_h_
#define __IRISSlicer_h_
#include <ImageCoordinateTransform.h>
#include "RLEImageRegionConstIterator.h"
#include <itkImageToImageFilter.h>
#include <itkImageSliceConstIteratorWithIndex.h>
#include <itkImageRegionIteratorWithIndex.h>
#include <itkImageLinearIteratorWithIndex.h>
/**
* \class IRISSlicer
* \brief A slice extraction filter for 3D images.
*
* This filter takes a transform
* from image space (x=pixel, y=line, z=slice) to display space. A slice
* shows either x-y, y-z, or x-z in the display space. This filter is necessary
* because the origin in the slice can correspond to any corner of the image, not
* just to the origin of the image. This filter can traverse the image in different
* directions, accomodating different positions of the display space origin in the
* image space.
*/
template <class TInputImage, class TOutputImage, class TPreviewImage>
class ITK_EXPORT IRISSlicer
: public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef IRISSlicer Self;
typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef TInputImage InputImageType;
typedef typename InputImageType::ConstPointer InputImagePointer;
typedef typename InputImageType::PixelType InputPixelType;
typedef typename InputImageType::InternalPixelType InputComponentType;
typedef TPreviewImage PreviewImageType;
typedef typename InputImageType::ConstPointer PreviewImagePointer;
typedef typename InputImageType::PixelType PreviewPixelType;
typedef typename InputImageType::InternalPixelType PreviewComponentType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointer;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::InternalPixelType OutputComponentType;
/** Method for creation through the object factory. */
itkNewMacro(Self)
/** Run-time type information (and related methods). */
itkTypeMacro(IRISSlicer, ImageToImageFilter)
/** Some more typedefs. */
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef itk::ImageSliceConstIteratorWithIndex<InputImageType> InputIteratorType;
typedef itk::ImageRegionIteratorWithIndex<OutputImageType> SimpleOutputIteratorType;
typedef itk::ImageLinearIteratorWithIndex<OutputImageType> OutputIteratorType;
/** Set the current slice index */
itkSetMacro(SliceIndex,unsigned int);
itkGetMacro(SliceIndex,unsigned int);
/** Set the image axis along which the subsequent slices lie */
itkSetMacro(SliceDirectionImageAxis,unsigned int);
itkGetMacro(SliceDirectionImageAxis,unsigned int);
/** Set the image axis along which the subsequent lines in a slice lie */
itkSetMacro(LineDirectionImageAxis,unsigned int);
itkGetMacro(LineDirectionImageAxis,unsigned int);
/** Set the image axis along which the subsequent pixels in a line lie */
itkSetMacro(PixelDirectionImageAxis,unsigned int);
itkGetMacro(PixelDirectionImageAxis,unsigned int);
/** Set the direction of line traversal */
itkSetMacro(LineTraverseForward,bool);
itkGetMacro(LineTraverseForward,bool);
/** Set the direction of pixel traversal */
itkSetMacro(PixelTraverseForward,bool);
itkGetMacro(PixelTraverseForward,bool);
/** Add a second `preview' input to the slicer. The slicer will check if
the preview input is newer than the main input, and if so, will obtain
the data from the preview input. This is used in the speed preview
framework, but could also be adapted for other features. Setting the
preview input to NULL disables this feature. */
void SetPreviewInput(PreviewImageType *input);
/**
Get the preview input.
*/
PreviewImageType *GetPreviewInput();
/**
* Indicate whether the main input should always be bypassed when the preview
* input is present. If not, the slicer will use whichever input is newer.
*/
itkGetMacro(BypassMainInput, bool)
itkSetMacro(BypassMainInput, bool)
protected:
IRISSlicer();
virtual ~IRISSlicer() {};
void PrintSelf(std::ostream &s, itk::Indent indent) const;
/**
* IRISSlicer can produce an image which is a different
* resolution than its input image. As such, IRISSlicer
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
virtual void GenerateOutputInformation();
void GenerateInputRequestedRegion();
/**
* This method maps an input region to an output region
*/
virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion,
const OutputImageRegionType &srcRegion);
/*
void BeforeThreadedGenerateData();
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread,
ThreadIdType threadId);
void AfterThreadedGenerateData();
*/
/**
* IRISSlicer is not implemented as a multithreaded filter.
* \sa ImageToImageFilter::GenerateData()
*/
virtual void GenerateData();
template <class TSourceImage> void DoGenerateData(const TSourceImage *source);
private:
IRISSlicer(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
// Current slice in each of the dimensions
unsigned int m_SliceIndex;
// Image axis corresponding to the slice direction
unsigned int m_SliceDirectionImageAxis;
// Image axis corresponding to the line direction
unsigned int m_LineDirectionImageAxis;
// Image axis corresponding to the pixel direction
unsigned int m_PixelDirectionImageAxis;
// Whether the line direction is reversed
bool m_LineTraverseForward;
// Whether the pixel direction is reversed
bool m_PixelTraverseForward;
// Whether the main input should always be bypassed
bool m_BypassMainInput;
// The worker methods in this filter
// void CopySliceLineForwardPixelForward(InputIteratorType, OutputImageType *);
// void CopySliceLineForwardPixelBackward(InputIteratorType, OutputImageType *);
// void CopySliceLineBackwardPixelForward(InputIteratorType, OutputImageType *);
// void CopySliceLineBackwardPixelBackward(InputIteratorType, OutputImageType *);
};
//specialization for run-length encoded image
template< typename TPixel, typename CounterType, class TOutputImage, class TPreviewImage>
class ITK_EXPORT IRISSlicer<RLEImage<TPixel, 3, CounterType>, TOutputImage, TPreviewImage >
: public itk::ImageToImageFilter<RLEImage<TPixel, 3, CounterType>, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef IRISSlicer Self;
typedef RLEImage<TPixel, 3, CounterType> InputImageType;
typedef itk::ImageToImageFilter<InputImageType, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename InputImageType::ConstPointer InputImagePointer;
typedef typename InputImageType::PixelType InputPixelType;
typedef typename InputImageType::InternalPixelType InputComponentType;
typedef TPreviewImage PreviewImageType;
typedef typename PreviewImageType::ConstPointer PreviewImagePointer;
typedef typename PreviewImageType::PixelType PreviewPixelType;
typedef typename PreviewImageType::InternalPixelType PreviewComponentType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointer;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::InternalPixelType OutputComponentType;
/** Method for creation through the object factory. */
itkNewMacro(Self)
/** Run-time type information (and related methods). */
itkTypeMacro(IRISSlicer, ImageToImageFilter)
/** Some more typedefs. */
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef itk::ImageSliceConstIteratorWithIndex<InputImageType> InputIteratorType;
typedef itk::ImageRegionIteratorWithIndex<OutputImageType> SimpleOutputIteratorType;
typedef itk::ImageLinearIteratorWithIndex<OutputImageType> OutputIteratorType;
/** Set the current slice index */
itkSetMacro(SliceIndex, unsigned int);
itkGetMacro(SliceIndex, unsigned int);
/** Set the image axis along which the subsequent slices lie */
itkSetMacro(SliceDirectionImageAxis, unsigned int);
itkGetMacro(SliceDirectionImageAxis, unsigned int);
/** Set the image axis along which the subsequent lines in a slice lie */
itkSetMacro(LineDirectionImageAxis, unsigned int);
itkGetMacro(LineDirectionImageAxis, unsigned int);
/** Set the image axis along which the subsequent pixels in a line lie */
itkSetMacro(PixelDirectionImageAxis, unsigned int);
itkGetMacro(PixelDirectionImageAxis, unsigned int);
/** Set the direction of line traversal */
itkSetMacro(LineTraverseForward, bool);
itkGetMacro(LineTraverseForward, bool);
/** Set the direction of pixel traversal */
itkSetMacro(PixelTraverseForward, bool);
itkGetMacro(PixelTraverseForward, bool);
/** Add a second `preview' input to the slicer. The slicer will check if
the preview input is newer than the main input, and if so, will obtain
the data from the preview input. This is used in the speed preview
framework, but could also be adapted for other features. Setting the
preview input to NULL disables this feature. */
void SetPreviewInput(PreviewImageType *input);
/**
Get the preview input.
*/
PreviewImageType *GetPreviewInput();
/**
* Indicate whether the main input should always be bypassed when the preview
* input is present. If not, the slicer will use whichever input is newer.
*/
itkGetMacro(BypassMainInput, bool)
itkSetMacro(BypassMainInput, bool)
protected:
IRISSlicer();
virtual ~IRISSlicer() {};
void PrintSelf(std::ostream &s, itk::Indent indent) const;
/**
* IRISSlicer can produce an image which is a different
* resolution than its input image. As such, IRISSlicer
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
virtual void GenerateOutputInformation();
void GenerateInputRequestedRegion();
/**
* This method maps an input region to an output region
*/
virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion,
const OutputImageRegionType &srcRegion);
void GenerateData();
//void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread,
// itk::ThreadIdType threadId);
/** Uncompresses a RLE line into a buffer pointed by out.
* After each pixel is written, adds stride to the pointer.
* The buffer needs to have enough room.
* No error checking is conducted. */
inline void uncompressLine(const typename InputImageType::RLLine & line, TPixel *out, long stride)
{
//complete Run-Length Lines have to be buffered
itkAssertOrThrowMacro(this->GetInput()->GetBufferedRegion().GetSize(0)
== this->GetInput()->GetLargestPossibleRegion().GetSize(0),
"BufferedRegion must contain complete run-length lines!");
#ifdef _DEBUG
int debugCount = 0;
#endif
for (int x = 0; x < line.size(); x++)
for (CounterType r = 0; r < line[x].first; r++)
{
#ifdef _DEBUG
debugCount++;
assert(debugCount <= this->GetInput()->GetLargestPossibleRegion().GetSize(0));
#endif
*out = line[x].second;
out += stride;
}
}
private:
IRISSlicer(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
// Current slice in each of the dimensions
unsigned int m_SliceIndex;
// Image axis corresponding to the slice direction
unsigned int m_SliceDirectionImageAxis;
// Image axis corresponding to the line direction
unsigned int m_LineDirectionImageAxis;
// Image axis corresponding to the pixel direction
unsigned int m_PixelDirectionImageAxis;
// Whether the line direction is reversed
bool m_LineTraverseForward;
// Whether the pixel direction is reversed
bool m_PixelTraverseForward;
// Whether the main input should always be bypassed
bool m_BypassMainInput;
};
#ifndef ITK_MANUAL_INSTANTIATION
#include "IRISSlicer.txx"
#include "IRISSlicer_RLE.txx"
#endif
#endif //__IRISSlicer_h_
|