ITK  4.4.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 >
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  itkSetObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
144  itkGetModifiableObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
146 
149  void SetObjectToWorldTransform(TransformType *transform);
150  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
152 
153  itkGetModifiableObjectMacro(IndexToWorldTransform, TransformType);
154 
159 
162 
164  unsigned long GetTransformMTime(void);
165 
167  unsigned long GetWorldTransformMTime(void);
168 
170  virtual bool ValueAt(const PointType & point, double & value,
171  unsigned int depth = 0,
172  char *name = NULL) const;
173 
180  virtual bool IsEvaluableAt(const PointType & point,
181  unsigned int depth = 0,
182  char *name = NULL) const;
183 
185  virtual bool IsInside(const PointType & point,
186  unsigned int depth = 0,
187  char *name = NULL) const;
188 
193  bool Evaluate(const PointType & point) const
194  {
195  return this->IsInside(point);
196  }
197 
199  virtual void DerivativeAt(const PointType & point,
200  short unsigned int order,
201  OutputVectorType & value,
202  unsigned int depth = 0,
203  char *name = NULL);
204 
207  ModifiedTimeType GetMTime(void) const;
208 
211  unsigned long GetObjectMTime(void) const
212  {
213  return Superclass::GetMTime();
214  }
215 
222  virtual void SetLargestPossibleRegion(const RegionType & region);
223 
230  virtual const RegionType & GetLargestPossibleRegion() const
231  { return m_LargestPossibleRegion; }
232 
236  virtual void SetBufferedRegion(const RegionType & region);
237 
241  virtual const RegionType & GetBufferedRegion() const
242  { return m_BufferedRegion; }
243 
248  virtual void SetRequestedRegion(const RegionType & region);
249 
254  virtual void SetRequestedRegion(const DataObject *data);
255 
260  virtual const RegionType & GetRequestedRegion() const
261  { return m_RequestedRegion; }
262 
272  const OffsetValueType * GetOffsetTable() const { return m_OffsetTable; }
274 
278  {
279  // need to add bounds checking for the region/buffer?
280  OffsetValueType offset = 0;
281  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
283 
284  // data is arranged as [][][][slice][row][col]
285  // with Index[0] = col, Index[1] = row, Index[2] = slice
286  for ( int i = VDimension - 1; i > 0; i-- )
287  {
288  offset += ( ind[i] - bufferedRegionIndex[i] ) * m_OffsetTable[i];
289  }
290  offset += ( ind[0] - bufferedRegionIndex[0] );
291 
292  return offset;
293  }
294 
298  {
299  IndexType index;
300  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
302 
303  for ( int i = VDimension - 1; i > 0; i-- )
304  {
305  index[i] = static_cast< IndexValueType >( offset / m_OffsetTable[i] );
306  offset -= ( index[i] * m_OffsetTable[i] );
307  index[i] += bufferedRegionIndex[i];
308  }
309  index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
310 
311  return index;
312  }
313 
323  virtual void CopyInformation(const DataObject *data);
324 
332  virtual void UpdateOutputInformation();
333 
338 
349 
358  virtual bool VerifyRequestedRegion();
359 
361  PropertyType * GetProperty(void);
362 
363  const PropertyType * GetProperty(void) const { return m_Property; }
364 
366  void SetProperty(PropertyType *property);
367 
369  itkGetConstReferenceMacro(Id, int);
370  itkSetMacro(Id, int);
372 
374  itkSetMacro(ParentId, int);
375  itkGetConstReferenceMacro(ParentId, int);
377 
379  virtual void Update(void);
380 
382  itkSetObjectMacro(TreeNode, TreeNodeType)
383 
384 
385  itkGetModifiableObjectMacro(TreeNode, TreeNodeType);
386 
390  void SetSpacing(const double spacing[itkGetStaticConstMacro(ObjectDimension)])
391  {
392  m_AffineGeometryFrame->GetModifiableIndexToObjectTransform()->SetScale(spacing);
393  this->Modified();
394  }
395 
397  virtual const double * GetSpacing() const
398  {
399  return this->GetIndexToObjectTransform()->GetScale();
400  }
401 
407  const TransformType * GetIndexToObjectTransform(void) const;
408 
410  {
411  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
412  }
414  {
415  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
416  }
417 
418 
422  void SetObjectToParentTransform(TransformType *transform);
423 
425 
426  const TransformType * GetObjectToParentTransform(void) const;
427 
432 
433  const TransformType * GetObjectToNodeTransform(void) const;
434 
439  void AddSpatialObject(Self *pointer);
440 
445  void RemoveSpatialObject(Self *object);
446 
448  virtual const Self * GetParent(void) const;
449 
451  virtual Self * GetParent(void);
452 
458  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
459  char *name = NULL) const;
460 
462  unsigned int GetNumberOfChildren(unsigned int depth = 0,
463  char *name = NULL) const;
464 
466  void SetChildren(ChildrenListType & children);
467 
470  virtual void Clear(void);
471 
494  virtual bool ComputeBoundingBox() const;
495 
496  virtual bool ComputeLocalBoundingBox() const
497  {
498  std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
499  << std::endl;
500  return false;
501  }
502 
505  virtual BoundingBoxType * GetBoundingBox() const;
506 
508  itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
509  itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
511 
514  itkSetMacro(BoundingBoxChildrenName, std::string);
515  itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
517 
520  void SetParent(Self *parent);
521 
524 
526 
527  const TransformType * GetNodeToParentNodeTransform(void) const;
528 
531  itkSetMacro(DefaultInsideValue, double);
532  itkGetConstMacro(DefaultInsideValue, double);
534 
537  itkSetMacro(DefaultOutsideValue, double);
538  itkGetConstMacro(DefaultOutsideValue, double);
540 
543  virtual std::string GetSpatialObjectTypeAsString() const;
544 
545 protected:
546 
548  SpatialObject();
549 
551  virtual ~SpatialObject();
552 
553  virtual void PrintSelf(std::ostream & os, Indent indent) const;
554 
559  void ComputeOffsetTable();
560 
561  itkSetMacro(Dimension, unsigned int);
562  itkGetConstReferenceMacro(Dimension, unsigned int)
563  itkSetMacro(TypeName, std::string);
564  itkGetModifiableObjectMacro(Bounds, BoundingBoxType);
565  itkGetModifiableObjectMacro(InternalInverseTransform, TransformType);
566 
574 
575 private:
576 
577  SpatialObject(const Self &); //purposely not implemented
578  void operator=(const Self &); //purposely not implemented
579 
582 
586 
588  std::string m_TypeName;
589 
590  unsigned int m_Dimension;
591 
593 
597 
601 
603  int m_Id;
605 
608 
611 
615 
619 
622 
625 };
626 } // end of namespace itk
627 
628 #if !defined( CABLE_CONFIGURATION )
629 #ifndef ITK_MANUAL_INSTANTIATION
630 #include "itkSpatialObject.hxx"
631 #endif
632 #endif
633 
634 #endif // __itkSpatialObject_h
635