This file is indexed.

/usr/include/InsightToolkit/SpatialObject/itkTubeSpatialObject.txx is in libinsighttoolkit3-dev 3.20.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkTubeSpatialObject.txx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  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 __itkTubeSpatialObject_txx
#define __itkTubeSpatialObject_txx

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkTubeSpatialObject.h" 

namespace itk  
{ 

/** Constructor */
template< unsigned int TDimension, typename TTubePointType >
TubeSpatialObject< TDimension, TTubePointType >
::TubeSpatialObject()  
{ 
  m_Root = false;
  m_Artery = true;
  m_ParentPoint = -1;
  this->SetDimension(TDimension);
  this->SetTypeName("TubeSpatialObject");
  this->GetProperty()->SetRed(1); 
  this->GetProperty()->SetGreen(0); 
  this->GetProperty()->SetBlue(0); 
  this->GetProperty()->SetAlpha(1);
  m_OldMTime = 0;
  m_IndexToWorldTransformMTime = 0;
  m_EndType = 0; // default end-type is flat
} 
 
/** Destructor */
template< unsigned int TDimension, typename TTubePointType >
TubeSpatialObject< TDimension, TTubePointType >  
::~TubeSpatialObject()
{ 
} 
 

/** Get the list of points composing the tube */
template< unsigned int TDimension, typename TTubePointType >
typename TubeSpatialObject< TDimension, TTubePointType >::PointListType &  
TubeSpatialObject< TDimension, TTubePointType > 
::GetPoints() 
{ 
  itkDebugMacro( "Getting TubePoint list" );
  return m_Points;
} 


/** Get the list of points composing the tube */
template< unsigned int TDimension, typename TTubePointType >
const typename 
TubeSpatialObject< TDimension, TTubePointType >::PointListType &  
TubeSpatialObject< TDimension, TTubePointType > 
::GetPoints() const
{ 
  itkDebugMacro( "Getting TubePoint list" );
  return m_Points;
} 

/** Set the list of points composing the tube */
template< unsigned int TDimension, typename TTubePointType >
void  
TubeSpatialObject< TDimension, TTubePointType >  
::SetPoints( PointListType & points )  
{
  // in this function, passing a null pointer as argument will
  // just clear the list...
  m_Points.clear();
         
  typename PointListType::iterator it,end;
  it = points.begin();
  end = points.end();
  while(it != end)
    {
    m_Points.push_back(*it);
    it++;
    }
   
  this->ComputeBoundingBox();
  this->Modified();
}

/** Remove the list of tube points */
template< unsigned int TDimension, typename TTubePointType >
void  
TubeSpatialObject< TDimension, TTubePointType >  
::Clear(void)
{
  m_Points.clear();
}

/** Print the object */ 
template< unsigned int TDimension, typename TTubePointType >
void  
TubeSpatialObject< TDimension, TTubePointType >  
::PrintSelf( std::ostream& os, Indent indent ) const 
{ 
  os << indent << "TubeSpatialObject(" << this << ")" << std::endl; 
  os << indent << "ID: " << this->GetId() << std::endl; 
  os << indent << "nb of points: "
     << static_cast<unsigned long>( m_Points.size()) << std::endl;
  os << indent << "End Type : " << m_EndType << std::endl;
  os << indent << "Parent Point : " << m_ParentPoint << std::endl; 
  os << indent << "Root : " << m_Root << std::endl; 
  os << indent << "Artery : " << m_Artery << std::endl; 
  Superclass::PrintSelf( os, indent ); 
} 
 
/** Compute the bounds of the tube */  
template< unsigned int TDimension, typename TTubePointType >
bool 
TubeSpatialObject< TDimension, TTubePointType >  
::ComputeLocalBoundingBox() const
{ 
  itkDebugMacro( "Computing tube bounding box" );

  // Check if the IndexToWorldTransform or the object itself has been modified
  if( (this->GetMTime() == m_OldMTime)
     && (m_IndexToWorldTransformMTime == 
                                 this->GetIndexToWorldTransform()->GetMTime())
    )
    {
    return true; // if not modified we return
    }
 
  m_OldMTime = this->GetMTime();
  m_IndexToWorldTransformMTime = this->GetIndexToWorldTransform()->GetMTime();
   
  if( this->GetBoundingBoxChildrenName().empty() 
    || strstr(typeid(Self).name(), this->GetBoundingBoxChildrenName().c_str()) )
    {
    typename PointListType::const_iterator it  = m_Points.begin();
    typename PointListType::const_iterator end = m_Points.end();

    if(it == end)
      {
      return false;
      }
    else
      {
      // First we compute the bounding box in the index space
      typename BoundingBoxType::Pointer bb = BoundingBoxType::New();
      PointType ptMin = (*it).GetPosition()-(*it).GetRadius();
      PointType ptMax = (*it).GetPosition()+(*it).GetRadius();
      bb->SetMinimum(ptMin);
      bb->SetMaximum(ptMax);

      ptMin = this->GetIndexToWorldTransform()->TransformPoint(ptMin);
      const_cast<BoundingBoxType *>(this->GetBounds())->SetMinimum(ptMin);
      ptMax = this->GetIndexToWorldTransform()->TransformPoint(ptMax);
      const_cast<BoundingBoxType *>(this->GetBounds())->SetMaximum(ptMax);

      it++;
      while(it!= end) 
       {
        ptMin = (*it).GetPosition()-(*it).GetRadius();
        ptMax = (*it).GetPosition()+(*it).GetRadius();
        bb->ConsiderPoint(ptMin);
        bb->ConsiderPoint(ptMax);
        it++;
        }

      typedef typename BoundingBoxType::PointsContainer PointsContainer;
      const PointsContainer * corners = bb->GetCorners();
      typename BoundingBoxType::PointsContainer::const_iterator 
                                                     itBB = corners->begin();
      while(itBB != corners->end())
        {
        PointType pnt = 
                     this->GetIndexToWorldTransform()->TransformPoint(*itBB);
        const_cast<BoundingBoxType *>(this->GetBounds())->ConsiderPoint(pnt);
        ++itBB;
        }
      }
    }
  return true;
} 

/** Test whether a point is inside or outside the object 
 *  For computational speed purposes, it is faster if the method does not
 *  check the name of the class and the current depth */ 
template< unsigned int TDimension, typename TTubePointType >
bool 
TubeSpatialObject< TDimension, TTubePointType >
::IsInside( const PointType & point) const
{
  this->ComputeLocalBoundingBox();
  if( !this->GetBounds()->IsInside(point) )
    {
    return false;
    }

  double minSquareDist=999999.0;
  double tempSquareDist;
  typename PointListType::const_iterator it = m_Points.begin();
  typename PointListType::const_iterator it2 = m_Points.begin();
  typename PointListType::const_iterator end = m_Points.end(); 
  typename PointListType::const_iterator min;
  
  if( !this->SetInternalInverseTransformToWorldToIndexTransform() )
    {
    return false;
    }

  PointType transformedPoint = 
    this->GetInternalInverseTransform()->TransformPoint(point);
       
  if(m_EndType == 0) // flat end-type
    {
    it2++; // next point 
    while(it2!= end)
      {
      // Check if the point is on the normal plane
      PointType a = (*it).GetPosition();
      PointType b = (*it2).GetPosition();
      
      double A = 0;
      double B = 0;

      for(unsigned int i = 0;i<TDimension;i++)
        {
        A += (b[i]-a[i])*(transformedPoint[i]-a[i]);
        B += (b[i]-a[i])*(b[i]-a[i]);
        }

      double lambda = A/B;

      if( ((it != m_Points.begin()) && 
          (lambda>-((*it).GetRadius()/(2*vcl_sqrt(B))))
          && (lambda<0))
          || ((lambda <= 1.0) && (lambda >= 0.0))
        )
        {
        PointType p;

        if(lambda >= 0)
          {
          for(unsigned int i = 0;i<TDimension;i++)
            {
            p[i] = a[i]+lambda*(b[i]-a[i]);
            }
          }
        else
          {
          for(unsigned int i = 0;i<TDimension;i++)
            {
            p[i] = b[i]+lambda*(b[i]-a[i]);
            }
          }

        tempSquareDist=transformedPoint.EuclideanDistanceTo(p);
        
        double R;
        if(lambda >= 0)
          {
          R = (*it).GetRadius()+lambda*((*it2).GetRadius()-(*it).GetRadius());
          }
        else
          {
          R = (*it2).GetRadius()+lambda*((*it2).GetRadius()-(*it).GetRadius());
          }

        if(tempSquareDist <= R)
          {
          return true;
          }
        }
        it++;
        it2++;
      }
    }
  else if(m_EndType == 1) // rounded end-type
    {
    while(it!= end)
      {
      tempSquareDist=transformedPoint.SquaredEuclideanDistanceTo(
        (*it).GetPosition());
      if(tempSquareDist <= minSquareDist) 
         {
         minSquareDist = tempSquareDist;
         min = it;
         }
     it++;
     }

     double dist = vcl_sqrt(minSquareDist);
     if( dist <= ((*min).GetRadius()) ) 
       {
       return true;
       }
     }
  return false;
}


/** Return true if the given point is inside the tube */
template< unsigned int TDimension, typename TTubePointType >
bool 
TubeSpatialObject< TDimension, TTubePointType >  
::IsInside( const PointType & point, unsigned int depth, char * name) const
{
  itkDebugMacro( "Checking the point [" << point << "] is inside the tube" );
 
  if(name == NULL)
    {
    if(IsInside(point))
      {
      return true;
      }
    }
  else if(strstr(typeid(Self).name(), name))
    {
    if(IsInside(point))
      {
      return true;
      }
    }
  
  return Superclass::IsInside(point, depth, name);

}

/** Remove duplicate points */
template< unsigned int TDimension, typename TTubePointType >
unsigned int  
TubeSpatialObject< TDimension, TTubePointType > 
::RemoveDuplicatePoints(unsigned int itkNotUsed(step))
{
  int length = this->GetNumberOfPoints();
  if(length <= 1)
    {
    return 0;
    }

  int nPoints = 0;
  for(int i=0; i < length-1; i++)
    {
    if(this->GetPoint(i)->GetPosition() == this->GetPoint(i+1)->GetPosition())
      {
      this->RemovePoint(i+1);
      i--;
      length--;
      nPoints++;
      }
    if(i >= 0 && i < length-2 &&
       this->GetPoint(i)->GetPosition() == this->GetPoint(i+2)->GetPosition())
      {
      this->RemovePoint(i+2);
      i--;
      length--;
      nPoints++;
      }
    }

  return nPoints;
}


/** Compute the tangent of the centerline of the tube */ 
template< unsigned int TDimension, typename TTubePointType >
bool  
TubeSpatialObject< TDimension, TTubePointType >  
::ComputeTangentAndNormals( void ) 
{ 
  itkDebugMacro( "Computing the tangent vectors of the tube" );
 
  int length = this->GetNumberOfPoints();
  if( length == 0 )
    {
    return false; 
    }
  
  PointType x1, x3; 
  VectorType t;
  double l; 
  t.Fill(0.0);
 
  if( length == 1 ) 
    { 
    ((TubePointType *)(this->GetPoint(0)))->SetTangent(t); 
    return true; 
    } 
     
  unsigned int it1 = 0;
  unsigned int it2 = 1;
  unsigned int it3 = 2;
   
  while(it3 < (unsigned int)length)
    {
    x1 = this->GetPoint(it1)->GetPosition();
    x3 = this->GetPoint(it3)->GetPosition();
    l=0;
    for(unsigned int i=0; i<TDimension; i++)
      {
      t[i] = (x3[i] - x1[i]);
      l = l + t[i]*t[i];
      }
    
    l = vcl_sqrt(l);
    if(l == 0)
      {
      std::cerr << "TubeSpatialObject::ComputeTangentAndNormals() : "; 
      std::cerr << "length between two consecutive points is 0";
      std::cerr << " (use RemoveDuplicatePoints())" << std::endl;
      std::cerr << "   p1 = " << x1 << std::endl;
      std::cerr << "   p3 = " << x3 << std::endl;
      return false;
      }
    for(unsigned int i=0; i<TDimension; i++)
      {
      t[i] /= l;
      }
 
    ((TubePointType*)(this->GetPoint(it2)))->SetTangent(t);
    it1++;
    it2++;
    it3++;
    }
 
  it1 = 0;
  it2 = 1;
  t = ((TubePointType*)(this->GetPoint(it2)))->GetTangent();
  ((TubePointType*)(this->GetPoint(it1)))->SetTangent(t);
  it1 = length-1;
  it2 = length-2;
  t = ((TubePointType*)(this->GetPoint(it2)))->GetTangent();
  ((TubePointType*)(this->GetPoint(it1)))->SetTangent(t);
 

  // Compute the normal
  CovariantVectorType n1;
  CovariantVectorType n2; 
    
  it1 = 0;
  while(it1 < (unsigned int)length)
    {
    t = ((TubePointType*)(this->GetPoint(it1)))->GetTangent(); 
 
    if (TDimension == 2)
      { 
      t = ((TubePointType*)(this->GetPoint(it1)))->GetTangent(); 
      n1[0] = -t[1];
      n1[1] = t[0];
      ((TubePointType*)(this->GetPoint(it1)))->SetNormal1(n1); 
      }
    else if (TDimension == 3)
      {
      n1[0] = -t[1];
      n1[1] = t[0];
      n1[2] = 0;

      if(n1[0]+n1[1]+n1[2] == 0.0) // if the normal is null
        {
          n1[0] = 0;
          n1[1] = -t[2];
          n1[2] = t[1];
        }
      
      n2[0] = t[1]*n1[2]-t[2]*n1[1];
      n2[1] = t[2]*n1[0]-t[0]*n1[2];
      n2[2] = t[0]*n1[1]-t[1]*n1[0];
     
      ((TubePointType*)(this->GetPoint(it1)))->SetNormal1(n1);
      ((TubePointType*)(this->GetPoint(it1)))->SetNormal2(n2);
      }

    it1++;
    }
 
  it1 = 0;
  it2 = 1;
  n1 = ((TubePointType*)(this->GetPoint(it2)))->GetNormal1();
  ((TubePointType*)(this->GetPoint(it1)))->SetNormal1(n1);
   
  if (TDimension == 3)
    {
    n2 = ((TubePointType*)(this->GetPoint(it2)))->GetNormal2();
    ((TubePointType*)(this->GetPoint(it1)))->SetNormal2(n2);
    }
   
  it1 = length-1;
  it2 = length-2;
  n1 = ((TubePointType*)(this->GetPoint(it2)))->GetNormal1();
  ((TubePointType*)(this->GetPoint(it1)))->SetNormal1(n1);
   
  if (TDimension == 3)
    {
    n2 = ((TubePointType*)(this->GetPoint(it2)))->GetNormal2();
    ((TubePointType*)(this->GetPoint(it1)))->SetNormal2(n2);  
    }

  return true; 
} 

/** Return true if the tube is evaluable at a given point */
template< unsigned int TDimension, typename TTubePointType >
bool
TubeSpatialObject< TDimension, TTubePointType > 
::IsEvaluableAt( const PointType & point, 
                 unsigned int depth, char * name ) const
{
  itkDebugMacro( "Checking if the tube is evaluable at " << point );
  return IsInside(point, depth, name);
}

/** Return the value of the tube at a specified point */
template< unsigned int TDimension, typename TTubePointType >
bool
TubeSpatialObject< TDimension, TTubePointType > 
::ValueAt( const PointType & point, double & value, unsigned int depth,
           char * name ) const
{
  itkDebugMacro( "Getting the value of the tube at " << point );
  if( IsInside(point, 0, name) )
    {
    value = this->GetDefaultInsideValue();
    return true;
    }
  else
    {
    if( Superclass::IsEvaluableAt(point, depth, name) )
      {
      Superclass::ValueAt(point, value, depth, name);
      return true;
      }
    else
      {
      value = this->GetDefaultOutsideValue();
      return false;
      }
    }
  return false;
}


/** Copy the information from another spatial object */
template< unsigned int TDimension, typename TTubePointType >
void
TubeSpatialObject< TDimension, TTubePointType > 
::CopyInformation(const DataObject *data)
{
  // check if we are the same type
  const Self* source = dynamic_cast<const Self*>(data);
  if(!source)
    {
    std::cout << "CopyInformation: objects are not of the same type" 
              << std::endl;
    return;
    }

  // copy the properties
  Superclass::CopyInformation(data);

  // copy the internal info
  this->SetRoot(source->GetRoot());
  this->SetArtery(source->GetArtery());
  this->SetParentPoint(source->GetParentPoint());
  this->SetEndType(source->GetEndType());

  // We copy the points
  PointListType source_list = source->GetPoints();
  typename PointListType::const_iterator it_source = source_list.begin();

  this->m_Points.clear();

  while(it_source != source_list.end())
    {
    this->m_Points.push_back(*it_source);
    it_source++;
    }

}

} // end namespace itk 

#endif // end __itkTubeSpatialObject_txx