ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkSpatialObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkSpatialObject_h
19 #define __itkSpatialObject_h
20 
21 // Disable warning for lengthy symbol names in this file only
22 
23 #include "itkAffineGeometryFrame.h"
24 #include "itkCovariantVector.h"
25 #include "itkExceptionObject.h"
26 #include <list>
28 #include "itkProcessObject.h"
29 #include "itkIndex.h"
30 #include "itkImageRegion.h"
32 
33 namespace itk
34 {
55 template< unsigned int VDimension >
56 class SpatialObjectTreeNode;
57 
58 template< unsigned int VDimension = 3 >
60  public DataObject
61 {
62 public:
63 
64  typedef double ScalarType;
65 
66  itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
67 
70  unsigned int GetMaximumDepth() const { return MaximumDepth; }
71 
74 
77 
79  // Spatial Function Iterator needs the following typedef
82 
86 
87  typedef double *SpacingType;
88 
91 
95 
97 
100 
103 
105  typedef std::list< Pointer > ChildrenListType;
107 
110 
118 
120 
123  virtual bool HasParent(void) const;
124 
126  virtual const char * GetTypeName(void) const { return m_TypeName.c_str(); }
127 
131  itkStaticConstMacro(ObjectDimension, unsigned int, VDimension);
132 
134  unsigned int GetObjectDimension(void) const { return VDimension; }
135 
137  itkNewMacro(Self);
138 
140  itkTypeMacro(SpatialObject, DataObject);
141 
143  itkGetConstObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
144  itkSetObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
146 
149  void SetObjectToWorldTransform(TransformType *transform);
150 
151  itkGetObjectMacro(ObjectToWorldTransform, TransformType);
152  itkGetConstObjectMacro(ObjectToWorldTransform, TransformType);
153  itkGetObjectMacro(IndexToWorldTransform, TransformType);
154  itkGetConstObjectMacro(IndexToWorldTransform, TransformType);
155 
160 
163 
165  unsigned long GetTransformMTime(void);
166 
168  unsigned long GetWorldTransformMTime(void);
169 
171  virtual bool ValueAt(const PointType & point, double & value,
172  unsigned int depth = 0,
173  char *name = NULL) const;
174 
181  virtual bool IsEvaluableAt(const PointType & point,
182  unsigned int depth = 0,
183  char *name = NULL) const;
184 
186  virtual bool IsInside(const PointType & point,
187  unsigned int depth = 0,
188  char *name = NULL) const;
189 
194  bool Evaluate(const PointType & point) const
195  {
196  return this->IsInside(point);
197  }
198 
200  virtual void DerivativeAt(const PointType & point,
201  short unsigned int order,
202  OutputVectorType & value,
203  unsigned int depth = 0,
204  char *name = NULL);
205 
208  unsigned long GetMTime(void) const;
209 
212  unsigned long GetObjectMTime(void) const
213  {
214  return Superclass::GetMTime();
215  }
216 
223  virtual void SetLargestPossibleRegion(const RegionType & region);
224 
231  virtual const RegionType & GetLargestPossibleRegion() const
232  { return m_LargestPossibleRegion; }
233 
237  virtual void SetBufferedRegion(const RegionType & region);
238 
242  virtual const RegionType & GetBufferedRegion() const
243  { return m_BufferedRegion; }
244 
249  virtual void SetRequestedRegion(const RegionType & region);
250 
255  virtual void SetRequestedRegion(const DataObject *data);
256 
261  virtual const RegionType & GetRequestedRegion() const
262  { return m_RequestedRegion; }
263 
273  const OffsetValueType * GetOffsetTable() const { return m_OffsetTable; }
275 
279  {
280  // need to add bounds checking for the region/buffer?
281  OffsetValueType offset = 0;
282  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
284 
285  // data is arranged as [][][][slice][row][col]
286  // with Index[0] = col, Index[1] = row, Index[2] = slice
287  for ( int i = VDimension - 1; i > 0; i-- )
288  {
289  offset += ( ind[i] - bufferedRegionIndex[i] ) * m_OffsetTable[i];
290  }
291  offset += ( ind[0] - bufferedRegionIndex[0] );
292 
293  return offset;
294  }
295 
299  {
300  IndexType index;
301  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
303 
304  for ( int i = VDimension - 1; i > 0; i-- )
305  {
306  index[i] = static_cast< IndexValueType >( offset / m_OffsetTable[i] );
307  offset -= ( index[i] * m_OffsetTable[i] );
308  index[i] += bufferedRegionIndex[i];
309  }
310  index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
311 
312  return index;
313  }
314 
324  virtual void CopyInformation(const DataObject *data);
325 
333  virtual void UpdateOutputInformation();
334 
339 
350 
359  virtual bool VerifyRequestedRegion();
360 
362  PropertyType * GetProperty(void);
363 
364  const PropertyType * GetProperty(void) const { return m_Property; }
365 
367  void SetProperty(PropertyType *property);
368 
370  itkGetConstReferenceMacro(Id, int);
371  itkSetMacro(Id, int);
373 
375  itkSetMacro(ParentId, int);
376  itkGetConstReferenceMacro(ParentId, int);
378 
380  virtual void Update(void);
381 
383  itkSetObjectMacro(TreeNode, TreeNodeType)
384 
385 
386  itkGetObjectMacro(TreeNode, TreeNodeType);
387  itkGetConstObjectMacro(TreeNode, TreeNodeType);
389 
393  void SetSpacing(const double
394  spacing[itkGetStaticConstMacro(ObjectDimension)])
395  { this->GetIndexToObjectTransform()->SetScale(spacing); }
396 
398  virtual const double * GetSpacing() const
399  { return this->GetIndexToObjectTransform()->GetScale(); }
400 
407 
408  const TransformType * GetIndexToObjectTransform(void) const;
409 
413  void SetObjectToParentTransform(TransformType *transform);
414 
416 
417  const TransformType * GetObjectToParentTransform(void) const;
418 
423 
424  const TransformType * GetObjectToNodeTransform(void) const;
425 
430  void AddSpatialObject(Self *pointer);
431 
436  void RemoveSpatialObject(Self *object);
437 
439  virtual const Self * GetParent(void) const;
440 
442  virtual Self * GetParent(void);
443 
449  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
450  char *name = NULL) const;
451 
453  unsigned int GetNumberOfChildren(unsigned int depth = 0,
454  char *name = NULL) const;
455 
457  void SetChildren(ChildrenListType & children);
458 
461  virtual void Clear(void);
462 
485  virtual bool ComputeBoundingBox() const;
486 
487  virtual bool ComputeLocalBoundingBox() const
488  {
489  std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
490  << std::endl;
491  return false;
492  }
493 
496  virtual BoundingBoxType * GetBoundingBox() const;
497 
499  itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
500  itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
502 
505  itkSetMacro(BoundingBoxChildrenName, std::string);
506  itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
508 
511  void SetParent(Self *parent);
512 
515 
517 
518  const TransformType * GetNodeToParentNodeTransform(void) const;
519 
522  itkSetMacro(DefaultInsideValue, double);
523  itkGetConstMacro(DefaultInsideValue, double);
525 
528  itkSetMacro(DefaultOutsideValue, double);
529  itkGetConstMacro(DefaultOutsideValue, double);
531 
534  virtual std::string GetSpatialObjectTypeAsString() const;
535 
536 protected:
537 
539  SpatialObject();
540 
542  virtual ~SpatialObject();
543 
544  virtual void PrintSelf(std::ostream & os, Indent indent) const;
545 
550  void ComputeOffsetTable();
551 
552  itkSetMacro(Dimension, unsigned int);
553  itkGetConstReferenceMacro(Dimension, unsigned int)
554  itkSetMacro(TypeName, std::string);
555  itkGetConstObjectMacro(Bounds, BoundingBoxType);
556  itkGetConstObjectMacro(InternalInverseTransform, TransformType);
557 
565 
566 private:
567 
568  SpatialObject(const Self &); //purposely not implemented
569  void operator=(const Self &); //purposely not implemented
570 
572  mutable unsigned long m_BoundsMTime;
573 
577 
579  std::string m_TypeName;
580 
581  unsigned int m_Dimension;
582 
584 
588 
592 
594  int m_Id;
596 
599 
602 
606 
610 
613 
616 };
617 } // end of namespace itk
618 
619 #if !defined( CABLE_CONFIGURATION )
620 #ifndef ITK_MANUAL_INSTANTIATION
621 #include "itkSpatialObject.hxx"
622 #endif
623 #endif
624 
625 #endif // __itkSpatialObject_h
626