File: igstkSpatialObject.cxx

package info (click to toggle)
igstk 4.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 38,980 kB
  • sloc: cpp: 86,267; xml: 96; makefile: 75; python: 38
file content (154 lines) | stat: -rw-r--r-- 4,223 bytes parent folder | download | duplicates (2)
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
/*=========================================================================

  Program:   Image Guided Surgery Software Toolkit
  Module:    $RCSfile: igstkSpatialObject.cxx,v $
  Language:  C++
  Date:      $Date: 2009-06-15 21:05:38 $
  Version:   $Revision: 1.30 $

  Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
  See IGSTKCopyright.txt or http://www.igstk.org/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.

=========================================================================*/

#include "igstkSpatialObject.h"

namespace igstk
{ 

/** Constructor */
SpatialObject::SpatialObject():m_StateMachine(this)
{
  /** Coordinate system interface */
  igstkCoordinateSystemClassInterfaceConstructorMacro();

  this->m_SpatialObject = NULL;

  igstkAddInputMacro( InternalSpatialObjectNull );
  igstkAddInputMacro( InternalSpatialObjectValid );
  igstkAddInputMacro( RequestBounds );

  igstkAddStateMacro( Initial  );
  igstkAddStateMacro( Ready  );

  igstkAddTransitionMacro( Initial, InternalSpatialObjectNull, 
                           Initial, ReportSpatialObjectNull );
  igstkAddTransitionMacro( Initial, InternalSpatialObjectValid, 
                           Ready,   SetInternalSpatialObject );
  igstkAddTransitionMacro( Initial, RequestBounds, 
                           Initial, ReportBoundsNotAvailable );

  igstkAddTransitionMacro( Ready, RequestBounds, 
                           Ready, ReportBounds );

  igstkSetInitialStateMacro( Initial );
  this->m_StateMachine.SetReadyToRun();

} 

/** Destructor */
SpatialObject::~SpatialObject()  
{
}

/** Print Self function */
void SpatialObject::PrintSelf( std::ostream& os, itk::Indent indent ) const
{
  Superclass::PrintSelf(os, indent);

  if( this->m_SpatialObject )
    {
    os << indent << "Internal Spatial Object = ";
    os << this->m_SpatialObject.GetPointer() << std::endl;
    }
  os << indent << "CoordinateSystemDelegator: ";
  this->m_CoordinateSystemDelegator->PrintSelf( os, indent );
}

/** Request setting the ITK spatial object that provide internal 
 *  functionalities. */
void SpatialObject
::RequestSetInternalSpatialObject( SpatialObjectType * spatialObject )
{  
  this->m_SpatialObjectToBeSet = spatialObject;

  if( this->m_SpatialObjectToBeSet.IsNull() )
    {
    igstkPushInputMacro( InternalSpatialObjectNull );
    this->m_StateMachine.ProcessInputs();
    }
  else 
    {
    igstkPushInputMacro( InternalSpatialObjectValid );
    this->m_StateMachine.ProcessInputs();
    }
}
 

/** Set the ITK spatial object that provide internal functionalities.
 * This method should only be called from the StateMachine */
void SpatialObject::SetInternalSpatialObjectProcessing()
{
  this->m_SpatialObject = this->m_SpatialObjectToBeSet;
}

/** Return the internal pointer to the SpatialObject */
SpatialObject::SpatialObjectType * 
SpatialObject::GetInternalSpatialObject() const
{
  return this->m_SpatialObject;
}

void
SpatialObject
::RequestGetBounds() const
{
  igstkLogMacro( DEBUG, "SpatialObject::RequestGetBounds() called ....\n");
  Self * self = const_cast< Self * >( this );
  self->RequestGetBounds();
}

void
SpatialObject
::RequestGetBounds() 
{
  igstkLogMacro( DEBUG, "SpatialObject::RequestGetBounds() called ....\n");

  igstkPushInputMacro( RequestBounds );
  this->m_StateMachine.ProcessInputs();
}

void
SpatialObject
::ReportBoundsProcessing() 
{
  igstkLogMacro( DEBUG, "SpatialObject::ReportBoundsProcessing() called....\n");

  BoundingBoxEvent  event;
  event.Set( this->GetInternalSpatialObject()->GetBoundingBox() );
  this->InvokeEvent( event );
}

void
SpatialObject
::ReportBoundsNotAvailableProcessing()
{
  igstkLogMacro( WARNING, 
    "Spatial Object bounds are not available." );
  this->InvokeEvent( InvalidRequestErrorEvent() );
}

void
SpatialObject
::ReportSpatialObjectNullProcessing()
{
  igstkLogMacro( WARNING, 
    "Spatial object was NULL when trying to SetInternalSpatialObject." );
  this->InvokeEvent( InvalidRequestErrorEvent() );
}

} // end namespace igstk