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
|
/*=========================================================================
Program: ITK-SNAP
Module: $RCSfile: SnakeParametersPreviewPipeline.h,v $
Language: C++
Date: $Date: 2009/01/23 20:09:38 $
Version: $Revision: 1.4 $
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 __SnakeParametersPreviewPipeline_h_
#define __SnakeParametersPreviewPipeline_h_
#include "itkImage.h"
#include "itkRGBAPixel.h"
#include "itkCovariantVector.h"
#include "itkUnaryFunctorImageFilter.h"
#include "SnakeParameters.h"
#include "ColorMap.h"
#include "ImageWrapperTraits.h"
template <class TSpeedImageType, class TImageType> class SNAPLevelSetFunction;
template<class TFilter> class LevelSetExtensionFilter;
class vtkImageImport;
class vtkContourFilter;
class LevelSetPreviewPipeline2D;
class GlobalState;
namespace itk {
template<class TInputImage, class TOutputImage>
class ParallelSparseFieldLevelSetImageFilter;
};
class LevelSetPreview2d;
// #define SNAKE_PREVIEW_ADVANCED 1
/**
* \class SnakeParametersPreviewPipeline
* \brief A pipeline used to preview snake parameters.
*
* Given a set of control points an image, and some snake parameters, this
* class computes a b-spline curve based on those control points, creates a
* level set embedding of the curve, and computes various level set evolution
* forces acting on the curve.
*/
class SnakeParametersPreviewPipeline
{
public:
SnakeParametersPreviewPipeline(GlobalState *state);
virtual ~SnakeParametersPreviewPipeline();
// Images used by this class (internally and externally)
typedef itk::Image<unsigned char, 2> CharImageType;
typedef itk::Image<float, 2> FloatImageType;
typedef itk::Image<short, 2> ShortImageType;
// Define a color image for display
typedef itk::RGBAPixel<unsigned char> DisplayPixelType;
typedef itk::Image<DisplayPixelType,2> DisplayImageType;
// Index type used to refer to pixels
typedef FloatImageType::IndexType IndexType;
// Force types
enum ForceType {CURVATURE=0, ADVECTION, PROPAGATION, TOTAL };
// A sample from the curve
struct SampledPoint {
// The geometry of the point
double t;
Vector2d x;
Vector2d n;
double kappa;
// The forces acting on the point
double PropagationForce;
double CurvatureForce;
double AdvectionForce;
double operator[](unsigned int i) const
{ return x[i]; }
};
// Various list types
typedef std::vector<Vector2d> ControlPointList;
typedef std::vector<Vector2d> LevelSetContourType;
typedef std::vector<SampledPoint> SampledPointList;
/** Set the speed image */
void SetSpeedImage(ShortImageType *image);
/** Set the snake parameters */
void SetSnakeParameters(const SnakeParameters ¶meters);
/** Set the control points of the interface curve */
void SetControlPoints(const ControlPointList &points);
/** Change just one control point, with an option of changing it
* quickly, ie, not recomputing the level set, only the curve */
void ChangeControlPoint(unsigned int index, const Vector2d &point,
bool quickUpdate);
/** Set the number of points sampled for display of the curve */
void SetNumberOfSampledPoints(unsigned int number);
/** Update the internals of the pipeline and compute the curve and the
* force points. This method requires a GL context because it relies on
* GL tesselation code for generating an image from the curve */
void Update();
/** Get the speed image */
irisGetMacro(SpeedImage, ShortImageType *);
/** Get a reference to the control points of the interface curve */
irisGetMacro(ControlPoints,const ControlPointList &);
/** Get a list of densely interpolated points on the curve (for drawing) */
irisGetMacro(SampledPoints,const SampledPointList &);
/** Get the demo loop contour */
std::vector<Vector2d> &GetDemoLoopContour();
/** Get the color image corresponding to the speed image */
DisplayImageType *GetDisplayImage()
{ return m_DisplayMapper->GetOutput(); }
/** Set the idle callback function that FLTK should call in demo mode */
void AnimationCallback();
/** Have the animation restart on the next callback */
void AnimationRestart();
private:
/** The global state */
GlobalState *m_GlobalState;
/** The speed image */
itk::SmartPointer<ShortImageType> m_SpeedImage;
// Gradient image used by this component
typedef itk::CovariantVector<float,2> VectorType;
typedef itk::Image<VectorType,2> VectorImageType;
typedef itk::SmartPointer<VectorImageType> VectorImagePointer;
/** The grandient of the speed image */
VectorImagePointer m_GradientImage;
/** A set of snake parameters */
SnakeParameters m_Parameters;
/** A list of control points */
ControlPointList m_ControlPoints;
/** Number of points to sample from the curve */
unsigned int m_NumberOfSampledPoints;
/** A list of sampled points */
SampledPointList m_SampledPoints;
// Flags indicating which part of the pipeline should be refreshed
bool m_ControlsModified;
bool m_SpeedModified;
bool m_ParametersModified;
bool m_QuickUpdate;
// Internal components of the Update method
void UpdateLevelSetFunction();
void UpdateContour();
void UpdateLevelSet();
void UpdateForces();
// A filter used to convert the speed image to a color image to display on the screen
class SimpleColorMapFunctor
{
public:
ColorMap::RGBAType operator()(short in)
{
float t = (in - m_SpeedMin) / (m_SpeedMax - m_SpeedMin);
return m_ColorMap->MapIndexToRGBA(t);
}
SimpleColorMapFunctor()
{
m_ColorMap = ColorMap::New();
m_ColorMap->SetToSystemPreset(ColorMap::COLORMAP_SPEED);
SpeedImageWrapperTraits::GetFixedIntensityRange(m_SpeedMin, m_SpeedMax);
}
private:
SmartPtr<ColorMap> m_ColorMap;
float m_SpeedMin, m_SpeedMax;
};
typedef itk::UnaryFunctorImageFilter<
ShortImageType,DisplayImageType,SimpleColorMapFunctor> IntensityFilterType;
typedef itk::SmartPointer<IntensityFilterType> IntensityFilterPointer;
IntensityFilterPointer m_DisplayMapper;
// Demo loop object
LevelSetPreview2d *m_DemoLoop;
};
#endif // __SnakeParametersPreviewPipeline_h_
|