File: igstkBoxObjectRepresentation.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 (176 lines) | stat: -rw-r--r-- 5,002 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*=========================================================================

  Program:   Image Guided Surgery Software Toolkit
  Module:    $RCSfile: igstkBoxObjectRepresentation.cxx,v $
  Language:  C++
  Date:      $Date: 2008-02-11 01:41:50 $
  Version:   $Revision: 1.6 $

  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 "igstkBoxObjectRepresentation.h"
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>


namespace igstk
{ 

/** Constructor */
BoxObjectRepresentation::BoxObjectRepresentation():m_StateMachine(this)
{
  igstkLogMacro( DEBUG, "Constructor called ....\n");

  // We create the ellipse spatial object
  m_BoxSpatialObject = NULL;
  this->RequestSetSpatialObject( m_BoxSpatialObject );
  m_BoxSource = vtkCubeSource::New();
  
  igstkAddInputMacro( ValidBoxObject );
  igstkAddInputMacro( NullBoxObject  );

  igstkAddStateMacro( NullBoxObject  );
  igstkAddStateMacro( ValidBoxObject );

  igstkAddTransitionMacro( NullBoxObject, NullBoxObject, NullBoxObject,  No );
  igstkAddTransitionMacro( NullBoxObject, ValidBoxObject, 
                           ValidBoxObject, SetBoxObject );
  igstkAddTransitionMacro( ValidBoxObject, NullBoxObject, NullBoxObject,  No ); 
  igstkAddTransitionMacro( ValidBoxObject, ValidBoxObject, 
                           ValidBoxObject,  No ); 

  igstkSetInitialStateMacro( NullBoxObject );

  m_StateMachine.SetReadyToRun();
} 

/** Destructor */
BoxObjectRepresentation::~BoxObjectRepresentation()  
{
  igstkLogMacro( DEBUG, "Destructor called ....\n");

  if( m_BoxSource )
    {
    m_BoxSource->Delete();
    m_BoxSource = NULL;
    }
  this->DeleteActors();
}

/** Set the Box Spatial Object */
void BoxObjectRepresentation
::RequestSetBoxObject( const BoxSpatialObjectType * box )
{
  igstkLogMacro( DEBUG, "RequestSetBoxObject called ....\n");

  m_BoxObjectToAdd = box;
  if( !m_BoxObjectToAdd )
    {
    igstkPushInputMacro( NullBoxObject );
    m_StateMachine.ProcessInputs();
    }
  else
    {
    igstkPushInputMacro( ValidBoxObject );
    m_StateMachine.ProcessInputs();
    }
}


/** No Processing */
void BoxObjectRepresentation::NoProcessing()
{
  igstkLogMacro( DEBUG, "NoProcessing called ....\n");
}


/** Set the Box Spatial Object */
void BoxObjectRepresentation::SetBoxObjectProcessing()
{
  igstkLogMacro( DEBUG, "SetBoxObjectProcessing called ....\n");

  // We create the ellipse spatial object
  m_BoxSpatialObject = m_BoxObjectToAdd;
  this->RequestSetSpatialObject( m_BoxSpatialObject );

  if( m_BoxSource != NULL )
    {
    m_BoxSource->SetCenter(0, 0, 0);
    m_BoxSource->SetXLength(m_BoxSpatialObject->GetSizeX());
    m_BoxSource->SetYLength(m_BoxSpatialObject->GetSizeY());
    m_BoxSource->SetZLength(m_BoxSpatialObject->GetSizeZ());
    }
} 

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

  if( this->m_BoxSource )
    {
    os << indent << this->m_BoxSource << std::endl;
    }
}


/** Update the visual representation in response to changes in the geometric
 * object */
void BoxObjectRepresentation::UpdateRepresentationProcessing()
{
  igstkLogMacro( DEBUG, "UpdateRepresentationProcessing called ....\n");

  m_BoxSource->SetXLength(m_BoxSpatialObject->GetSizeX());
  m_BoxSource->SetYLength(m_BoxSpatialObject->GetSizeY());
  m_BoxSource->SetZLength(m_BoxSpatialObject->GetSizeZ());
}


/** Create the vtk Actors */
void BoxObjectRepresentation::CreateActors()
{
  igstkLogMacro( DEBUG, "CreateActors called ....\n");

  // to avoid duplicates we clean the previous actors
  this->DeleteActors();
   
  vtkPolyDataMapper *boxMapper = vtkPolyDataMapper::New();
  vtkActor* boxActor = vtkActor::New();

  boxActor->GetProperty()->SetColor(this->GetRed(),
                                         this->GetGreen(),
                                         this->GetBlue()); 
        
  boxActor->GetProperty()->SetOpacity(this->GetOpacity()); 
  boxMapper->SetInput(m_BoxSource->GetOutput());
  boxActor->SetMapper( boxMapper );

  // We should check if the actor doesn't exist
  this->AddActor( boxActor );
  boxMapper->Delete();
}

/** Create a copy of the current object representation */
BoxObjectRepresentation::Pointer
BoxObjectRepresentation::Copy() const
{
  igstkLogMacro( DEBUG, "Copy() called ....\n");

  Pointer newOR = BoxObjectRepresentation::New();
  newOR->SetColor(this->GetRed(),this->GetGreen(),this->GetBlue());
  newOR->SetOpacity(this->GetOpacity());
  newOR->RequestSetBoxObject(m_BoxSpatialObject);

  return newOR;
}

} // end namespace igstk