Orfeo Toolbox  3.16
itkSpatialObject.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSpatialObject.txx,v $
5  Language: C++
6  Date: $Date: 2009-01-28 20:10:27 $
7  Version: $Revision: 1.77 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkSpatialObject_txx
19 #define __itkSpatialObject_txx
20 
21 #include "itkSpatialObject.h"
22 #include "itkNumericTraits.h"
23 #include <algorithm>
24 #include <string>
25 
26 namespace itk
27 {
28 
30 template< unsigned int TDimension >
33 {
34  m_TypeName = "SpatialObject";
35  m_Dimension = TDimension;
36  m_Bounds = BoundingBoxType::New();
37  m_BoundsMTime = 0;
38  m_Property = PropertyType::New();
39  m_TreeNode = NULL;
40 
41  m_ObjectToWorldTransform = TransformType::New();
42  m_ObjectToWorldTransform->SetIdentity();
43  m_ObjectToParentTransform = TransformType::New();
44  m_ObjectToParentTransform->SetIdentity();
45  m_IndexToWorldTransform = TransformType::New();
46  m_IndexToWorldTransform->SetIdentity();
47 
48  m_BoundingBoxChildrenDepth=MaximumDepth;
49  m_Id = -1;
50  m_ParentId = -1;
51  m_AffineGeometryFrame = AffineGeometryFrameType::New();
52  m_AffineGeometryFrame->SetIndexToWorldTransform(m_IndexToWorldTransform);
54  m_TreeNode->Set(this);
55  m_InternalInverseTransform = TransformType::New();
56  m_DefaultInsideValue = 1.0;
57  m_DefaultOutsideValue = 0.0;
58 }
59 
61 template< unsigned int TDimension >
64 {
65  this->Clear();
66 }
67 
70 template< unsigned int TDimension >
71 void
73 ::Clear(void)
74 {
75  typename ChildrenListType::iterator pos = m_InternalChildrenList.begin();
76  typename ChildrenListType::iterator it = m_InternalChildrenList.begin();
77  while( it != m_InternalChildrenList.end() )
78  {
79  pos = it;
80  it++;
81  m_InternalChildrenList.erase(pos);
82  }
83  m_InternalChildrenList.clear();
84 }
85 
87 template< unsigned int TDimension >
88 void
90 ::DerivativeAt( const PointType & point, short unsigned int order,
91  OutputVectorType & value, unsigned int depth, char * name )
92 {
93  if( !IsEvaluableAt(point, depth, name) )
94  {
95  itk::ExceptionObject e("SpatialObject.txx");
96  e.SetLocation("SpatialObject< TDimension >::DerivateAt(\
97  const PointType, unsigned short, OutputVectorType & )");
98  e.SetDescription("This spatial object is not evaluable at the point");
99  throw e;
100  }
101 
102  if( order == 0 )
103  {
104  double r;
105 
106  ValueAt(point, r, depth, name);
107  value.Fill(r);
108  }
109  else
110  {
111  PointType p1,p2;
112  OutputVectorType v1,v2;
113  typename OutputVectorType::Iterator it = value.Begin();
114  typename OutputVectorType::Iterator it_v1 = v1.Begin();
115  typename OutputVectorType::Iterator it_v2 = v2.Begin();
116 
117  for( unsigned short i=0; i<TDimension; i++, it++, it_v1++, it_v2++ )
118  {
119  p1=point;
120  p2=point;
121 
122  // should get the spacing from the transform
123  const double * spacing = this->GetIndexToObjectTransform()->GetScale();
124  p1[i] -= spacing[i];
125  p2[i] += spacing[i];
126 
127  try
128  {
129  DerivativeAt(p1,order-1,v1, depth, name);
130  DerivativeAt(p2,order-1,v2, depth, name);
131  }
132  catch( itk::ExceptionObject e )
133  {
134  throw e;
135  }
136 
137  (*it) = ((*it_v2)-(*it_v1))/2;
138  }
139  }
140 }
141 
143 template< unsigned int TDimension >
144 bool
146 ::IsInside( const PointType & point, unsigned int depth, char * name) const
147 {
148  if( depth > 0 )
149  {
150  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
151  TreeChildrenListType* children = m_TreeNode->GetChildren();
152  typename TreeChildrenListType::const_iterator it = children->begin();
153  typename TreeChildrenListType::const_iterator itEnd = children->end();
154 
155  while(it!=itEnd)
156  {
157  if( (*it)->Get()->IsInside(point, depth-1, name) )
158  {
159  delete children;
160  return true;
161  }
162  it++;
163  }
164  delete children;
165  }
166 
167  return false;
168 }
169 
171 template< unsigned int TDimension >
172 bool
174 ::IsEvaluableAt( const PointType & point, unsigned int depth,
175  char * name ) const
176 {
177  if( depth > 0 )
178  {
179  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
180  TreeChildrenListType* children = m_TreeNode->GetChildren();
181  typename TreeChildrenListType::const_iterator it = children->begin();
182  typename TreeChildrenListType::const_iterator itEnd = children->end();
183 
184  while(it!=itEnd)
185  {
186  if( (*it)->Get()->IsEvaluableAt(point, depth-1, name) )
187  {
188  delete children;
189  return true;
190  }
191  it++;
192  }
193  delete children;
194  }
195 
196  return false;
197 }
198 
200 template< unsigned int TDimension >
201 bool
203 ::ValueAt( const PointType & point, double & value, unsigned int depth,
204  char * name ) const
205 {
206  bool evaluable = false;
207  if( depth > 0 )
208  {
209  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
210  TreeChildrenListType* children = m_TreeNode->GetChildren();
211  typename TreeChildrenListType::const_iterator it = children->begin();
212  typename TreeChildrenListType::const_iterator itEnd = children->end();
213 
214  while(it!=itEnd)
215  {
216  if( (*it)->Get()->IsEvaluableAt(point, depth-1, name) )
217  {
218  (*it)->Get()->ValueAt(point,value, depth-1, name);
219  evaluable = true;
220  break;
221  }
222  it++;
223  }
224  delete children;
225  }
226 
227  if(evaluable)
228  {
229  return true;
230  }
231  return false;
232 }
233 
235 template< unsigned int TDimension >
236 void
238 ::PrintSelf( std::ostream& os, Indent indent ) const
239 {
240  Superclass::PrintSelf(os, indent);
241  os << "Bounding Box:" << std::endl;
242  os << indent << m_Bounds << std::endl;
243  os << "Geometric properties:" << std::endl;
244  os << indent << "Object to World Transform: " << m_ObjectToWorldTransform
245  << std::endl;
246  os << indent << "Index to World Transform: " << m_IndexToWorldTransform
247  << std::endl;
248  os << std::endl << std::endl;
249  os << indent << "Bounding Box Children Depth: " << m_BoundingBoxChildrenDepth
250  << std::endl;
251  os << indent << "Bounding Box Children Name: " << m_BoundingBoxChildrenName
252  << std::endl;
253  os << "Object properties: " << std::endl;
254  os << m_Property << std::endl;
255 }
256 
258 template< unsigned int TDimension >
262 {
263  return m_Bounds.GetPointer();
264 }
265 
267 template< unsigned int TDimension >
268 void
271 {
272  m_TreeNode->AddChild(pointer->GetTreeNode());
273  m_InternalChildrenList.push_back(pointer);
274  this->Modified();
275 }
276 
278 template< unsigned int TDimension >
279 void
282 {
283  if(m_TreeNode->Remove(pointer->GetTreeNode()))
284  {
285  typename ChildrenListType::iterator pos;
286  pos = std::find(m_InternalChildrenList.begin(),
287  m_InternalChildrenList.end(), pointer );
288  if ( pos != m_InternalChildrenList.end() )
289  {
290  m_InternalChildrenList.erase(pos);
291  }
292  this->Modified();
293  }
294  else
295  {
296  std::cerr << "Cannot RemoveSpatialObject" << std::endl;
297  }
298 }
299 
300 
302 template< unsigned int TDimension >
303 void
306 {
307  static_cast<TreeNodeType*>(
308  m_TreeNode.GetPointer())->SetNodeToParentNodeTransform(transform);
309  ComputeObjectToWorldTransform();
310 }
311 
313 template< unsigned int TDimension >
314 void
317 {
318  // The ObjectToParentTransform is the combination of the
319  // ObjectToNodeTransform and the NodeToParentNodeTransform
320  m_ObjectToParentTransform->SetIdentity();
321  m_ObjectToParentTransform->SetCenter(
322  m_AffineGeometryFrame->GetObjectToNodeTransform()->GetCenter());
323  m_ObjectToParentTransform->Compose(
324  m_AffineGeometryFrame->GetObjectToNodeTransform(),false);
325  m_ObjectToParentTransform->Compose(
326  static_cast<TreeNodeType*>(
327  m_TreeNode.GetPointer())->GetNodeToParentNodeTransform(),false);
328 
329  m_ObjectToWorldTransform->SetCenter(
330  m_AffineGeometryFrame->GetObjectToNodeTransform()->GetCenter());
331  m_ObjectToWorldTransform->SetMatrix(
332  m_AffineGeometryFrame->GetObjectToNodeTransform()->GetMatrix());
333  m_ObjectToWorldTransform->SetOffset(
334  m_AffineGeometryFrame->GetObjectToNodeTransform()->GetOffset());
335 
336  m_IndexToWorldTransform->SetCenter(
337  m_AffineGeometryFrame->GetIndexToObjectTransform()->GetCenter());
338  m_IndexToWorldTransform->SetMatrix(
339  m_AffineGeometryFrame->GetIndexToObjectTransform()->GetMatrix());
340  m_IndexToWorldTransform->SetOffset(
341  m_AffineGeometryFrame->GetIndexToObjectTransform()->GetOffset());
342 
343  static_cast<TreeNodeType*>(m_TreeNode.GetPointer())
344  ->ComputeNodeToWorldTransform();
345  m_ObjectToWorldTransform->Compose(
346  static_cast<TreeNodeType*>(
347  m_TreeNode.GetPointer())->GetNodeToWorldTransform(),false);
348 
349  m_IndexToWorldTransform->Compose(this->GetObjectToWorldTransform(),false);
350 
351  // Propagate the changes to the children
352  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
353  TreeChildrenListType* children = m_TreeNode->GetChildren();
354  typename TreeChildrenListType::const_iterator it = children->begin();
355  typename TreeChildrenListType::const_iterator itEnd = children->end();
356 
357  while(it!=itEnd)
358  {
359  (*it)->Get()->ComputeObjectToWorldTransform();
360  it++;
361  }
362  delete children;
363 }
364 
366 template< unsigned int TDimension >
370 {
371  return m_AffineGeometryFrame->GetObjectToNodeTransform();
372 }
373 
375 template< unsigned int TDimension >
379 {
380  return m_AffineGeometryFrame->GetObjectToNodeTransform();
381 }
382 
384 template< unsigned int TDimension >
388 {
389  return static_cast<TreeNodeType*>(
390  m_TreeNode.GetPointer())->GetNodeToParentNodeTransform();
391  //return m_ObjectToNodeTransform.GetPointer();
392 }
393 
395 template< unsigned int TDimension >
399 {
400  return static_cast<TreeNodeType*>(
401  m_TreeNode.GetPointer())->GetNodeToParentNodeTransform();
402 }
403 
405 template< unsigned int TDimension >
409 {
410  return m_AffineGeometryFrame->GetIndexToObjectTransform();
411 }
412 
414 template< unsigned int TDimension >
418 {
419  return m_AffineGeometryFrame->GetIndexToObjectTransform();
420 }
421 
423 template< unsigned int TDimension >
424 void
427 {
428  m_ObjectToWorldTransform = transform;
429  ComputeObjectToParentTransform();
430 }
431 
434 template< unsigned int TDimension >
435 void
438 {
439 
440  m_ObjectToParentTransform->SetScale(m_ObjectToWorldTransform->GetScale());
441  m_ObjectToParentTransform->SetCenter(m_ObjectToWorldTransform->GetCenter());
442  m_ObjectToParentTransform->SetMatrix(m_ObjectToWorldTransform->GetMatrix());
443  m_ObjectToParentTransform->SetOffset(m_ObjectToWorldTransform->GetOffset());
444 
445  if(m_TreeNode->HasParent())
446  {
447  typename TransformType::Pointer inverse = TransformType::New();
448  if(static_cast<TreeNodeType*>(m_TreeNode->GetParent())
449  ->GetNodeToParentNodeTransform()->GetInverse(inverse))
450  {
451  m_ObjectToParentTransform->Compose(inverse,true);
452  }
453  }
454 
455  m_AffineGeometryFrame->GetObjectToNodeTransform()->SetIdentity();
456  static_cast<TreeNodeType*>(m_TreeNode.GetPointer())
457  ->GetNodeToParentNodeTransform()
458  ->SetCenter(m_ObjectToParentTransform->GetCenter());
459  static_cast<TreeNodeType*>(m_TreeNode.GetPointer())
460  ->GetNodeToParentNodeTransform()
461  ->SetMatrix(m_ObjectToParentTransform->GetMatrix());
462  static_cast<TreeNodeType*>(m_TreeNode.GetPointer())
463  ->GetNodeToParentNodeTransform()
464  ->SetOffset(m_ObjectToParentTransform->GetOffset());
465 
466  m_IndexToWorldTransform->SetCenter(m_AffineGeometryFrame
467  ->GetIndexToObjectTransform()
468  ->GetCenter());
469  m_IndexToWorldTransform->SetMatrix(m_AffineGeometryFrame
470  ->GetIndexToObjectTransform()
471  ->GetMatrix());
472  m_IndexToWorldTransform->SetOffset(m_AffineGeometryFrame
473  ->GetIndexToObjectTransform()
474  ->GetOffset());
475  m_IndexToWorldTransform->Compose(m_ObjectToWorldTransform,false);
476 }
477 
479 template< unsigned int TDimension >
480 unsigned long
482 ::GetMTime( void ) const
483 {
484  unsigned long latestTime = Object::GetMTime();
485 
486  if( latestTime < m_BoundsMTime )
487  {
488  latestTime = m_BoundsMTime;
489  }
490  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
491 
492  if(!m_TreeNode)
493  {
494  return latestTime;
495  }
496 
497  TreeChildrenListType* children = m_TreeNode->GetChildren();
498  typename TreeChildrenListType::const_iterator it = children->begin();
499  typename TreeChildrenListType::const_iterator itEnd = children->end();
500  unsigned long localTime;
501 
502  while(it!=itEnd)
503  {
504  localTime = (*it)->Get()->GetMTime();
505 
506  if( localTime > latestTime )
507  {
508  latestTime = localTime;
509  }
510  it++;
511  }
512  delete children;
513  return latestTime;
514 }
515 
537 template< unsigned int TDimension >
538 bool
541 {
542  itkDebugMacro( "Computing Bounding Box" );
543  this->ComputeLocalBoundingBox();
544 
545  if( m_BoundingBoxChildrenDepth > 0 && m_TreeNode)
546  {
547  typedef typename TreeNodeType::ChildrenListType TreeChildrenListType;
548  TreeChildrenListType* children = m_TreeNode->GetChildren(0);
549  typename TreeChildrenListType::const_iterator it = children->begin();
550  typename TreeChildrenListType::const_iterator itEnd = children->end();
551 
552  while(it!=itEnd)
553  {
554  (*it)->Get()->SetBoundingBoxChildrenDepth(m_BoundingBoxChildrenDepth-1);
555  (*it)->Get()->SetBoundingBoxChildrenName(m_BoundingBoxChildrenName);
556  (*it)->Get()->ComputeBoundingBox();
557 
558  // If the bounding box is not defined we set the minimum and maximum
559  bool bbDefined = false;
560  for(unsigned int i=0;i<m_Dimension;i++)
561  {
562  if(m_Bounds->GetBounds()[2*i] != 0
563  || m_Bounds->GetBounds()[2*i+1] != 0)
564  {
565  bbDefined = true;
566  break;
567  }
568  }
569 
570  if(!bbDefined)
571  {
572  m_Bounds->SetMinimum((*it)->Get()->GetBoundingBox()->GetMinimum());
573  m_Bounds->SetMaximum((*it)->Get()->GetBoundingBox()->GetMaximum());
574  }
575  else
576  {
577  m_Bounds->ConsiderPoint((*it)->Get()->GetBoundingBox()->GetMinimum());
578  m_Bounds->ConsiderPoint((*it)->Get()->GetBoundingBox()->GetMaximum());
579  }
580  it++;
581  }
582  delete children;
583  return true;
584  }
585 
586  typename BoundingBoxType::PointType pnt;
587  pnt.Fill( itk::NumericTraits< ITK_TYPENAME
588  BoundingBoxType::PointType::ValueType>::Zero );
589  m_Bounds->SetMinimum(pnt);
590  m_Bounds->SetMaximum(pnt);
591  m_BoundsMTime = this->GetMTime();
592  return false;
593 }
594 
598 template< unsigned int TDimension >
601 ::GetChildren( unsigned int depth, char * name) const
602 {
603  if(!m_TreeNode)
604  {
605  return 0;
606  }
607 
608  typename TreeNodeType::ChildrenListType* children =
609  m_TreeNode->GetChildren(depth,name);
610  typename TreeNodeType::ChildrenListType::const_iterator it =
611  children->begin();
612 
613  ChildrenListType * childrenSO = new ChildrenListType;
614 
615  while(it != children->end())
616  {
617  childrenSO->push_back((*it)->Get());
618  it++;
619  }
620 
621  delete children;
622  return childrenSO;
623 }
624 
626 template< unsigned int TDimension >
627 void
630 {
631  // Add children
632  typename ChildrenListType::iterator it = children.begin();
633  typename ChildrenListType::iterator itEnd = children.end();
634 
635  while(it != itEnd)
636  {
637  static_cast<TreeNodeType*>(
638  m_TreeNode.GetPointer())->AddChild((*it)->GetTreeNode());
639  it++;
640  }
641 }
642 
643 
645 template< unsigned int TDimension >
646 unsigned int
648 ::GetNumberOfChildren( unsigned int depth, char * name ) const
649 {
650  return m_TreeNode->GetNumberOfChildren(depth,name);
651 }
652 
654 template< unsigned int TDimension >
655 unsigned long
658 {
659  return m_ObjectToParentTransform->GetMTime();
660 }
661 
663 template< unsigned int TDimension >
664 unsigned long
667 {
668  return m_IndexToWorldTransform->GetMTime();
669 }
670 
671 
673 template< unsigned int TDimension >
676 ::GetParent( void )
677 {
678  if(m_TreeNode->HasParent())
679  {
680  return m_TreeNode->GetParent()->Get();
681  }
682  return NULL;
683 }
684 
686 template< unsigned int TDimension >
689 ::GetParent( void ) const
690 {
691  if(m_TreeNode->HasParent())
692  {
693  return m_TreeNode->GetParent()->Get();
694  }
695  return NULL;
696 }
697 
699 template< unsigned int TDimension >
700 void
702 ::SetParent( Self * parent )
703 {
704  if(!parent)
705  {
706  m_TreeNode->SetParent(NULL);
707  }
708  else
709  {
710  m_TreeNode->SetParent(parent->GetTreeNode());
711  }
712 }
713 
715 template< unsigned int TDimension >
716 bool
718 ::HasParent( void ) const
719 {
720  return m_TreeNode->HasParent();
721 }
722 
724 template< unsigned int TDimension >
725 void
728 {
729  if (m_LargestPossibleRegion != region)
730  {
731  m_LargestPossibleRegion = region;
732  this->Modified();
733  }
734 }
735 
737 template< unsigned int TDimension >
740 {
741  if (this->GetSource())
742  {
743  this->GetSource()->UpdateOutputInformation();
744  }
745  // If we don't have a source, then let's make our Image
746  // span our buffer
747  else
748  {
749  m_LargestPossibleRegion = m_BufferedRegion;
750  }
751 
752  // Now we should know what our largest possible region is. If our
753  // requested region was not set yet, (or has been set to something
754  // invalid - with no data in it ) then set it to the largest possible
755  // region.
756  if ( m_RequestedRegion.GetNumberOfPixels() == 0)
757  {
758  this->SetRequestedRegionToLargestPossibleRegion();
759  }
760 }
761 
762 template< unsigned int TDimension >
763 void
766 {
767  m_RequestedRegion = m_LargestPossibleRegion;
768 }
769 
770 
771 template< unsigned int TDimension >
772 bool
775 {
776  unsigned int i;
777  const IndexType &requestedRegionIndex = m_RequestedRegion.GetIndex();
778  const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
779 
780  const SizeType& requestedRegionSize = m_RequestedRegion.GetSize();
781  const SizeType& bufferedRegionSize = m_BufferedRegion.GetSize();
782 
783  for (i=0; i< m_Dimension; i++)
784  {
785  if ( (requestedRegionIndex[i] < bufferedRegionIndex[i]) ||
786  ((requestedRegionIndex[i] + static_cast<long>(requestedRegionSize[i]))
787  > (bufferedRegionIndex[i]
788  + static_cast<long>(bufferedRegionSize[i]))) )
789  {
790  return true;
791  }
792  }
793  return false;
794 }
795 
796 
797 template< unsigned int TDimension >
798 void
801 {
802  if (m_BufferedRegion != region)
803  {
804  m_BufferedRegion = region;
805  this->ComputeOffsetTable();
806  this->Modified();
807  }
808 }
809 
810 
811 template< unsigned int TDimension >
812 bool
815 {
816  bool retval = true;
817  unsigned int i;
818 
819  // Is the requested region within the LargestPossibleRegion?
820  // Note that the test is indeed against the largest possible region
821  // rather than the buffered region; see DataObject::VerifyRequestedRegion.
822  const IndexType &requestedRegionIndex = m_RequestedRegion.GetIndex();
823  const IndexType &largestPossibleRegionIndex
824  = m_LargestPossibleRegion.GetIndex();
825 
826  const SizeType& requestedRegionSize = m_RequestedRegion.GetSize();
827  const SizeType& largestPossibleRegionSize = m_LargestPossibleRegion.GetSize();
828 
829  for (i=0; i< m_Dimension; i++)
830  {
831  if ( (requestedRegionIndex[i] < largestPossibleRegionIndex[i]) ||
832  ((requestedRegionIndex[i] + static_cast<long>(requestedRegionSize[i]))
833  > (largestPossibleRegionIndex[i]
834  + static_cast<long>(largestPossibleRegionSize[i]))))
835  {
836  retval = false;
837  }
838  }
839 
840  return retval;
841 }
842 
843 template< unsigned int TDimension >
844 void
847 {
848  if (m_RequestedRegion != region)
849  {
850  m_RequestedRegion = region;
851  this->Modified();
852  }
853 }
854 
855 
856 template< unsigned int TDimension >
857 void
860 {
861  SpatialObject *imgData;
862 
863  imgData = dynamic_cast<SpatialObject*>(data);
864 
865  if (imgData)
866  {
867  m_RequestedRegion = imgData->GetRequestedRegion();
868  }
869  else
870  {
871  // pointer could not be cast back down
872  itkExceptionMacro(
873  << "itk::ImageBase::SetRequestedRegion(DataObject*) cannot cast "
874  << typeid(data).name() << " to " << typeid(SpatialObject*).name() );
875  }
876 }
877 
878 
879 template< unsigned int TDimension >
880 void
883 {
884  OffsetValueType num=1;
885  const SizeType& bufferSize = m_BufferedRegion.GetSize();
886 
887  m_OffsetTable[0] = static_cast<long int>( num );
888  for (unsigned int i=0; i < m_Dimension; i++)
889  {
890  num *= bufferSize[i];
891  m_OffsetTable[i+1] = static_cast<long int>( num );
892  }
893 }
894 
895 
896 template< unsigned int TDimension >
900 {
901  return m_Property;
902 }
903 
904 
905 template< unsigned int TDimension >
906 void
909 {
910  m_Property = property;
911 }
912 
913 template< unsigned int TDimension >
914 void
916 ::Update(void)
917 {
918  Superclass::Update();
919 
921  this->Modified();
922 }
923 
924 template< unsigned int TDimension >
925 bool
928 {
929  if(!this->GetIndexToWorldTransform()->GetInverse(
930  const_cast<TransformType *>(this->GetInternalInverseTransform())))
931  {
932  return false;
933  }
934  return true;
935 }
936 
937 template< unsigned int TDimension >
938 void
941 {
942  if(!m_TreeNode)
943  {
944  static_cast<TreeNodeType*>(
945  m_TreeNode.GetPointer())->SetNodeToParentNodeTransform(transform);
946  }
947 }
948 
949 template< unsigned int TDimension >
953 {
954  if(m_TreeNode)
955  {
956  return static_cast<TreeNodeType*>(
957  m_TreeNode.GetPointer())->GetNodeToParentNodeTransform();
958  }
959  return NULL;
960 }
961 
962 template< unsigned int TDimension >
966 {
967  if(m_TreeNode)
968  {
969  return static_cast<TreeNodeType*>(
970  m_TreeNode.GetPointer())->GetNodeToParentNodeTransform();
971  }
972  return NULL;
973 }
974 
977 template< unsigned int TDimension >
978 std::string
980 {
981  OStringStream n;
982  n << GetNameOfClass();
983  n << "_";
984  n << TDimension;
985  return n.str();
986 }
987 
988 
990 template< unsigned int TDimension >
993 {
994  // Standard call to the superclass' method
995  Superclass::CopyInformation(data);
996 
997  // Attempt to cast data to an ImageBase
998  const SpatialObject *imgData;
999 
1000  imgData = dynamic_cast<const SpatialObject*>(data);
1001 
1002  if (imgData)
1003  {
1004  // Copy the meta data for this data type
1005  m_LargestPossibleRegion = imgData->GetLargestPossibleRegion();
1006  }
1007  else
1008  {
1009  // pointer could not be cast back down
1010  itkExceptionMacro( << "itk::SpatialObject::CopyInformation() cannot cast "
1011  << typeid(data).name() << " to "
1012  << typeid(SpatialObject*).name() );
1013  }
1014 
1015  // check if we are the same type
1016  const Self* source = dynamic_cast<const Self*>(data);
1017  if(!source)
1018  {
1019  std::cout << "CopyInformation: objects are not of the same type"
1020  << std::endl;
1021  return;
1022  }
1023 
1024  // copy the properties
1025  this->GetProperty()->SetRed(source->GetProperty()->GetRed());
1026  this->GetProperty()->SetGreen(source->GetProperty()->GetGreen());
1027  this->GetProperty()->SetBlue(source->GetProperty()->GetBlue());
1028  this->GetProperty()->SetAlpha(source->GetProperty()->GetAlpha());
1029  this->GetProperty()->SetName(source->GetProperty()->GetName().c_str());
1030 
1031  // copy the ivars
1032  this->SetId(source->GetId());
1033  this->SetParentId(source->GetParentId());
1034 }
1035 
1036 } // end of namespace itk
1037 
1038 #endif // __SpatialObject_txx

Generated at Sun May 19 2013 00:08:41 for Orfeo Toolbox with doxygen 1.8.3.1