File: itkPolylineMaskImageFilter.txx

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (608 lines) | stat: -rw-r--r-- 21,285 bytes parent folder | download
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkPolylineMaskImageFilter.txx,v $
  Language:  C++
  Date:      $Date: 2008-01-20 18:00:40 $
  Version:   $Revision: 1.14 $

  Copyright (c) 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 _itkPolylineMaskImageFilter_txx
#define _itkPolylineMaskImageFilter_txx

#include "itkPolylineMaskImageFilter.h"
#include "itkRigid3DPerspectiveTransform.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkProgressReporter.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkResampleImageFilter.h"
#include "itkLineIterator.h"
#include "itkImageLinearIteratorWithIndex.h"
#include "itkPathIterator.h"
#include "itkVector.h"
#include "itkBoundingBox.h"

namespace itk
{
/**
 * Constructor
 */
template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::PolylineMaskImageFilter()
{
  this->SetNumberOfRequiredInputs( 2 );
  m_ViewVector.Fill(1);
  m_UpVector.Fill(1);
  m_CameraCenterPoint.Fill(0);
  m_FocalDistance = 0.0;
  m_FocalPoint.Fill( 0.0 );

  // This filter is meant only for 3D input and output images. We must
  // throw an exception otherwise.  
  if( (TInputImage::ImageDimension != 3) || (TOutputImage::ImageDimension !=3 ) )
    {
    itkExceptionMacro( << "PolylineMaskImageFilter must be templated over "
        << "input and output images of dimension 3" );
    }
  
  // View vectors must be of dimension 3
  if(TVector::Length != 3)
    {
    itkExceptionMacro( << "PolylineMaskImageFilter must be templated over "
        << "a view vector of length 3" );
    }
}

/**
 *
 */
  template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  void PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::SetInput1(const InputImageType *input)
  {
  // Process object is not const-correct so the const_cast is required here
  this->ProcessObject::SetNthInput(0,
                                   const_cast< InputImageType * >( input ) );
  }

/**
 *
 */
  template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  void PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::SetInput2(const PolylineType *input)
  {
  // Process object is not const-correct so the const_cast is required here
  this->ProcessObject::SetNthInput(1,
                                   const_cast< PolylineType * >( input ) );
  }

/**
 Generate 3D roatation matrix using the viewing and up vector
*/
  template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  void PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::GenerateRotationMatrix()
  {
    /* Normalize the view and up vector */
    TVector nUpVector; /* normalized Up vector */
    TVector nViewVector; /* normalized View vector */

    nUpVector = m_UpVector;
    nUpVector.Normalize();
    
    nViewVector = m_ViewVector;
    nViewVector.Normalize();

    itkDebugMacro(<<"Normalized Up vector" <<nUpVector);
    itkDebugMacro(<<"Normalized View vector"<<nViewVector);

    /* orthogonalize nUpVector and nViewVector */
    TVector nOrthogonalVector;

    nOrthogonalVector = nUpVector - (nViewVector*(nUpVector*nViewVector));

    itkDebugMacro(<<"Up vector component orthogonal to View vector "<<nOrthogonalVector);
    
    /* Perform cross product and determine a third coordinate axis
    orthogonal to both nOrthogonalVector and nViewVector */

    TVector nThirdAxis;
    nThirdAxis = CrossProduct(nOrthogonalVector,nViewVector);

    itkDebugMacro(<<"Third basis vector"<<nThirdAxis);

    /* populate the rotation matrix using the unit vectors of the
       camera reference coordinate system */

    m_RotationMatrix[0][0] = nThirdAxis[0];
    m_RotationMatrix[0][1] = nThirdAxis[1];
    m_RotationMatrix[0][2] = nThirdAxis[2]; 

    m_RotationMatrix[1][0] = nOrthogonalVector[0];
    m_RotationMatrix[1][1] = nOrthogonalVector[1];
    m_RotationMatrix[1][2] = nOrthogonalVector[2];

    m_RotationMatrix[2][0] = nViewVector[0];
    m_RotationMatrix[2][1] = nViewVector[1];
    m_RotationMatrix[2][2] = nViewVector[2];

  }

/**
 3D rotation and perspective projection transform
 */
template< class TInputImage, class TPolyline, class TVector, class TOutputImage>
typename PolylineMaskImageFilter< TInputImage,TPolyline,TVector,
         TOutputImage>::ProjPlanePointType 
PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
::TransformProjectPoint(PointType inputPoint)
{
  unsigned int i;
  PointType centered;

  // itkDebugMacro(<<"Point transforming"<<inputPoint);

  for(i=0;i<3;i++)
    { 
    centered[i] = inputPoint[i] - m_CameraCenterPoint[i];
    }

  PointType rotated =  m_RotationMatrix * centered;

  ProjPlanePointType result;

  double factor = m_FocalDistance / ( rotated[2] );
  
  result[0] = m_FocalPoint[0] + (rotated[0] * factor);
  result[1] = m_FocalPoint[1] + (rotated[1] * factor);

  // itkDebugMacro(<<"Point projected"<<result);

  return result;
}

/**
 *
 */
  template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  void PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::GenerateData(void)
  {

  typedef typename TInputImage::SizeType                              InputImageSizeType;
  typedef typename TInputImage::PointType                             InputImagePointType;
  typedef typename TInputImage::SpacingType                           InputImageSpacingType;
  typedef ImageRegionConstIterator<TInputImage>                       InputImageConstIteratorType;

  typedef typename TOutputImage::IndexType                            ImageIndexType;
  typedef typename TOutputImage::PixelType                            PixelType;
  typedef ImageRegionIterator<TOutputImage>                           OutputImageIteratorType;


  typedef typename TPolyline::Pointer                                 PolylinePointer;
  typedef typename TPolyline::VertexType                              VertexType;
  typedef typename TPolyline::VertexListType                          VertexListType;
  typedef typename TPolyline::IndexType                               PolylineIndexType;

  typedef Point<double,3>                                             OriginType;

  typename TInputImage::ConstPointer inputImagePtr(
    dynamic_cast<const TInputImage  * >(
      this->ProcessObject::GetInput(0)));
  typename TPolyline::ConstPointer polylinePtr(
    dynamic_cast<const TPolyline    * >(
      this->ProcessObject::GetInput(1)));
  typename TOutputImage::Pointer outputImagePtr(
    dynamic_cast<TOutputImage * >(
      this->ProcessObject::GetOutput(0)));


  outputImagePtr->SetSpacing(inputImagePtr->GetSpacing());

  OriginType originInput;

  originInput[0] = 0.0;
  originInput[1] = 0.0;
  originInput[2] = 0.0;
  
  //outputImagePtr->SetOrigin(inputImagePtr->GetOrigin());
  outputImagePtr->SetOrigin(originInput);
  outputImagePtr->SetRequestedRegion( inputImagePtr->GetRequestedRegion() );
  outputImagePtr->SetBufferedRegion(  inputImagePtr->GetBufferedRegion() );
  outputImagePtr->SetLargestPossibleRegion( inputImagePtr->GetLargestPossibleRegion() );
  outputImagePtr->Allocate();   
  outputImagePtr->FillBuffer(0);   

  InputImageConstIteratorType  inputIt(inputImagePtr,inputImagePtr->GetLargestPossibleRegion());
  OutputImageIteratorType outputIt(outputImagePtr,outputImagePtr->GetLargestPossibleRegion());

  typedef NearestNeighborInterpolateImageFunction< TInputImage, double> InterpolatorType;
  typedef typename InterpolatorType::OutputType OutputType;
  typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
  typedef typename InterpolatorType::PointType    InterpolatorPointType;


  /* Generate the transformation matrix */
  this->GenerateRotationMatrix();
 
  // Generate input and output point 
  InterpolatorPointType inputPoint;
  ProjPlanePointType outputPoint;
   
  // Generate a 2D image with the viewing polygon as a mask 
  typedef Image<PixelType,2> ProjectionImageType;
  typedef typename ProjectionImageType::IndexType          ProjectionImageIndexType;
  typedef typename ProjectionImageType::IndexValueType     ProjectionImageIndexValueType;
  typedef typename ProjectionImageType::PointType          ProjectionImagePointType;
  typedef typename ProjectionImageType::SpacingType        ProjectionImageSpacingType;
  typedef typename ProjectionImageType::PixelType          ProjectionImagePixelType;
  typedef typename ProjectionImageType::RegionType         ProjectionImageRegionType;
  typedef typename ProjectionImageType::SizeType           ProjectionImageSizeType;
  

  ProjectionImageRegionType projectionRegion;


  /* Determine projection image size by transforming the eight corner
   of the 3D input image */

  InputImageSizeType                                      inputImageSize;
  typedef Point<double, 3>                                CornerPointType;
  typedef Point<double, 2>                                CornerPointProjectionType;

  typedef BoundingBox< unsigned long int, 2, double > BoundingBoxType;
  typedef BoundingBoxType::PointsContainer                 CornerPointProjectionContainer;

  CornerPointProjectionContainer::Pointer                 cornerPointProjectionlist = CornerPointProjectionContainer::New();
  CornerPointType                                         cornerPoint;
  CornerPointType                                         originPoint;
  CornerPointProjectionType                               cornerProjectionPoint;

  originPoint[0] = 0.0;
  originPoint[1] = 0.0;
  originPoint[2] = 0.0;
  
  originPoint    = inputImagePtr->GetOrigin();
  inputImageSize = inputImagePtr->GetLargestPossibleRegion().GetSize();
  
  // (xmin,ymin,zmin)

  cornerPoint = originPoint;
  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

  // (xmin,ymin,zmax)
  cornerPoint[0] = originPoint[0];
  cornerPoint[1] = originPoint[1];
  cornerPoint[2] = originPoint[2] + inputImageSize[2];
  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

  // (xmin,ymax,zmin)
  cornerPoint[0] = originPoint[0];
  cornerPoint[1] = originPoint[1] + inputImageSize[1];
  cornerPoint[2] = originPoint[2];
  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;


// (xmin,ymax,zmax) 
  cornerPoint[0] = originPoint[0];
  cornerPoint[1] = originPoint[1] + inputImageSize[1];
  cornerPoint[2] = originPoint[2] + inputImageSize[2];;
  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

// (xmax,ymin,zmin)
  cornerPoint[0] = originPoint[0] + inputImageSize[0];
  cornerPoint[1] = originPoint[1] ;
  cornerPoint[2] = originPoint[2] ;

  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

// (xmax,ymin,zmax)
  cornerPoint[0] = originPoint[0] + inputImageSize[0];
  cornerPoint[1] = originPoint[1] ;
  cornerPoint[2] = originPoint[2] + inputImageSize[2];

  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

// (xmax,ymax,zmin)
  cornerPoint[0] = originPoint[0] + inputImageSize[0];
  cornerPoint[1] = originPoint[1] + inputImageSize[1];
  cornerPoint[2] = originPoint[2];

  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);


  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;

// (xmax,ymax,zmax)
  cornerPoint[0] = originPoint[0] + inputImageSize[0];
  cornerPoint[1] = originPoint[1] + inputImageSize[1];
  cornerPoint[2] = originPoint[2] + inputImageSize[2];;

  cornerProjectionPoint = this->TransformProjectPoint(cornerPoint);
  cornerPointProjectionlist->push_back(cornerProjectionPoint);

  //std::cout<<"CornerPoint="<<cornerPoint<<"\t"<<"ProjectedPoint="<<cornerProjectionPoint<<std::endl;
  
  /* Compute the bounding box of the projected points */
  BoundingBoxType::Pointer boundingBox = BoundingBoxType::New();

  boundingBox->SetPoints ( cornerPointProjectionlist );

  if ( !boundingBox->ComputeBoundingBox() )
    {
    itkExceptionMacro(<<"Bounding box computation error");
    }

  const BoundingBoxType::BoundsArrayType & bounds = boundingBox->GetBounds();
  itkDebugMacro(<< "Projection image bounding box="<<bounds);

  ProjectionImageIndexType  projectionStart; 
  projectionStart[0] = 0;
  projectionStart[1] = 0;

  ProjectionImageSizeType  projectionSize; 
  ProjectionImageIndexValueType pad;

  pad=5;

  projectionSize[0] = (ProjectionImageIndexValueType) (bounds[1]-bounds[0]) + pad;
  projectionSize[1] = (ProjectionImageIndexValueType) (bounds[3]-bounds[2]) + pad;

  projectionRegion.SetIndex(projectionStart);
  projectionRegion.SetSize(projectionSize);

  typename ProjectionImageType::Pointer projectionImagePtr = ProjectionImageType::New();

  ProjectionImagePointType origin;
  origin[0] = bounds[0];
  origin[1] = bounds[2];

  projectionImagePtr->SetOrigin(origin);

  ProjectionImageSpacingType spacing;

  spacing[0] = 1.0;
  spacing[1] = 1.0;

  projectionImagePtr->SetSpacing(spacing);

  itkDebugMacro(<<"Projection image size:"<<projectionSize);
  itkDebugMacro(<<"Projection image start index:"<<projectionStart);
  itkDebugMacro(<<"Projection image origin:"<<origin);

  projectionImagePtr->SetRequestedRegion( projectionRegion );
  projectionImagePtr->SetBufferedRegion(  projectionRegion );
  projectionImagePtr->SetLargestPossibleRegion( projectionRegion );
  projectionImagePtr->Allocate();   
  projectionImagePtr->FillBuffer(0);

  typedef ImageRegionIterator<ProjectionImageType>  ProjectionImageIteratorType;
  ProjectionImageIteratorType projectionIt(projectionImagePtr,projectionImagePtr->GetLargestPossibleRegion());

  itkDebugMacro(<<"Rotation matrix"<<std::cout<<m_RotationMatrix);

  typedef typename VertexListType::Pointer      VertexListPointer;
   
  const VertexListType * container      = polylinePtr->GetVertexList();

  typename VertexListType::ConstIterator piter = container->Begin();
    
  /* Rasterize each polyline segment using breshnan line iterator  */
    
  VertexType startIndex;
  VertexType endIndex;
  VertexType projectionIndex;
  VertexType pstartIndex;

  /* define flag to indicate the line segment slope */
  bool pflag;

  /* define background, foreground pixel values and unlabed pixel value */
  PixelType u_val = static_cast<ProjectionImagePixelType> (0);
  PixelType b_val = static_cast<ProjectionImagePixelType> (2);
  PixelType f_val = static_cast<ProjectionImagePixelType> (255);

  projectionImagePtr->FillBuffer(u_val);

  /* polyon start index */
  pstartIndex = piter.Value();
  projectionIndex = pstartIndex;
  ++piter;
  ProjectionImageIndexType startImageIndex;
  ProjectionImageIndexType endImageIndex;
  ProjectionImageIndexType projectionImageIndex;
    
  typedef typename ProjectionImageIndexType::IndexValueType IndexValueType;

  typedef LineIterator<ProjectionImageType>                    LineIteratorType;
  typedef ImageLinearIteratorWithIndex< ProjectionImageType >  ImageLineIteratorType;

  ImageLineIteratorType imit(projectionImagePtr, projectionImagePtr->GetLargestPossibleRegion());
  imit.SetDirection( 0 );

  while ( piter != container->End() )
    {
    pflag         = false;
    startIndex    = projectionIndex;
    endIndex      = piter.Value();

    for(unsigned int i=0; i < ProjectionImageType::ImageDimension; i++ )
      {
      startImageIndex[i] = static_cast<IndexValueType> (startIndex[i]);
      endImageIndex[i]   = static_cast<IndexValueType> (endIndex[i]);
      }


    if (endImageIndex[1] > startImageIndex[1]) 
      {
      pflag = true;
      }

    itkDebugMacro(<<"Polyline:"<<startImageIndex<<","<<endImageIndex);
    LineIteratorType      it(projectionImagePtr, startImageIndex, endImageIndex);
    it.GoToBegin();

    while (!it.IsAtEnd())
      {
      projectionImageIndex[0] = it.GetIndex()[0];
      projectionImageIndex[1] = it.GetIndex()[1];

      //initialize imit using it
      imit.SetIndex(projectionImageIndex);
      while ( ! imit.IsAtEndOfLine() )
        {
        if ( pflag ) 
          {
          if ( imit.Get() == u_val)
            {
            imit.Set(f_val);
            }
          }
        else 
          imit.Set(b_val);

        ++imit;
        }
      ++it;
      }
    projectionIndex = endIndex;
    ++piter;
    }

  /* Close the polygon */
  pflag         = false;
  startIndex    = projectionIndex;
  endIndex      = pstartIndex;
    
  for(unsigned int i=0; i < ProjectionImageType::ImageDimension; i++ )
    {
    startImageIndex[i] = static_cast<IndexValueType> (startIndex[i]);
    endImageIndex[i]   = static_cast<IndexValueType> (endIndex[i]);
    }

  if (endImageIndex[1] > startImageIndex[1]) 
    {
    pflag = true;
    }

  LineIteratorType      it(projectionImagePtr, startImageIndex, endImageIndex);
  it.GoToBegin();

  while (!it.IsAtEnd())
    {
    projectionImageIndex[0] = it.GetIndex()[0];
    projectionImageIndex[1] = it.GetIndex()[1];
    //initialize imit using it

    imit.SetIndex(projectionImageIndex);
    while ( ! imit.IsAtEndOfLine() )
      {
      if ( pflag ) 
        {
        if ( imit.Get() == u_val)
          {
          imit.Set(f_val);
          }
        }
      else 
        imit.Set(b_val);
      ++imit;
      }
    ++it;
    }

  //Mask the input image using the binary image defined by the region
  //demarcated by the polyline contour 
    outputIt.GoToBegin();
  inputIt.GoToBegin();

  InputImageSpacingType     inputImageSpacing;
  InputImagePointType       inputImageOrigin;

  inputImageSpacing  = inputImagePtr->GetSpacing();
  inputImageOrigin = inputImagePtr->GetOrigin();
  inputImageSize = inputImagePtr->GetLargestPossibleRegion().GetSize();
  
  while ( !inputIt.IsAtEnd() )
    {
    outputImagePtr->TransformIndexToPhysicalPoint( outputIt.GetIndex(), inputPoint );
    outputPoint = this->TransformProjectPoint(inputPoint);
    projectionImagePtr->TransformPhysicalPointToIndex(outputPoint,projectionImageIndex);

    //itkDebugMacro(<<"Input image (index,physical coordinate,pixel):"<<inputIt.GetIndex()<<","<<inputPoint<<inputIt.Get()<<std::endl);
    //itkDebugMacro(<<"Projection image (index,physical coordinate,pixel):"<<projectionImageIndex<<","<<outputPoint<<","<<projectionIt.Get()<<std::endl);

    // fileout<<inputIt.GetIndex()<<","<<inputPoint<<"="<<projectionImageIndex<<","<<outputPoint<<std::endl;
    if ( ! projectionImagePtr->GetBufferedRegion().IsInside(projectionImageIndex))
      {
      itkExceptionMacro(<<"Projection Image index out of bound:"<<projectionImageIndex);
      }
    
    if(projectionImagePtr->GetPixel(projectionImageIndex) == f_val)
      {
      outputIt.Set(inputIt.Get());
      }
    else
      {
      outputIt.Set(u_val);
      }

    ++inputIt;
    ++outputIt;
    }
  }

  template <class TInputImage, class TPolyline, class TVector,
          class TOutputImage>
  void PolylineMaskImageFilter<TInputImage,TPolyline,TVector,TOutputImage>
  ::PrintSelf(std::ostream& os, Indent indent) const
  {
  Superclass::PrintSelf(os,indent);
  os << indent << "Viewing vector: "
     << static_cast<typename NumericTraits<VectorType>::PrintType>(m_ViewVector)
     << std::endl;
  os << indent << "Up Vector: " 
     << static_cast<typename NumericTraits<VectorType>::PrintType>(m_UpVector)
     << std::endl;
  os << indent << "Camera Center Point: " << m_CameraCenterPoint << std::endl;
  os << indent << "Focal  Point       : " << m_FocalPoint        << std::endl;
  os << indent << "Focal Distance     : " << m_FocalDistance     << std::endl;
  os << indent << "Rotation matrix    : " << m_RotationMatrix   << std::endl;

  }
} // end namespace itk
#endif