vtkActor2D.cxx 5.28 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkActor2D.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$
  Thanks:    Thanks to Matt Turek who developed this class.

Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


=========================================================================*/
41
42
43
44
45

#include "vtkActor2D.h"
#include "vtkProperty2D.h"
#include "vtkMapper2D.h"

46
47
48
49
// Description:
// Creates an actor2D with the following defaults: 
// position -1, -1 (view coordinates)
// orientation 0, scale (1,1), layer 0, visibility on
50
51
52
53
54
55
56
57
58
59
vtkActor2D::vtkActor2D()
{
  this->Orientation = 0.0;
  this->Scale[0] = 1.0;
  this->Scale[1] = 1.0;
  this->LayerNumber = 0;
  this->Visibility = 1;  // ON
  this->SelfCreatedProperty = 0;
  this->Property = (vtkProperty2D*) NULL;
  this->Mapper = (vtkMapper2D*) NULL;
Ken Martin's avatar
Ken Martin committed
60
61
  this->PositionCoordinate = vtkCoordinate::New();
  this->PositionCoordinate->SetCoordinateSystem(VTK_VIEWPORT);
62
63
}

64
65
66
// Description:
// Destroy an actor2D.  If the actor2D created it's own
// property, that property is deleted.
67
68
vtkActor2D::~vtkActor2D()
{
Ken Martin's avatar
Ken Martin committed
69
  if (this->SelfCreatedProperty) this->Property->Delete();
70
71
  this->PositionCoordinate->Delete();
  this->PositionCoordinate = NULL;
72
73
74
75
}

void vtkActor2D::PrintSelf(ostream& os, vtkIndent indent)
{
Ken Martin's avatar
Ken Martin committed
76
  this->vtkReferenceCount::PrintSelf(os,indent);
77
78
79
80
81
  os << indent << "Orientation: " << this->Orientation << "\n";
  os << indent << "Scale: (" << this->Scale[0] << ", " << this->Scale[1] << ")\n";
  os << indent << "Layer Number: " << this->LayerNumber << "\n";
  os << indent << "Visibility: " << (this->Visibility ? "On\n" : "Off\n");

Ken Martin's avatar
Ken Martin committed
82
  os << indent << "PositionCoordinate: " << this->PositionCoordinate << "\n";
83
  this->PositionCoordinate->PrintSelf(os, indent.GetNextIndent());
Ken Martin's avatar
Ken Martin committed
84
  
85
86
87
88
89
  os << indent << "Self Created Property: " << (this->SelfCreatedProperty ? "Yes\n" : "No\n");
  os << indent << "Property: " << this->Property << "\n";
  if (this->Property) this->Property->PrintSelf(os, indent.GetNextIndent());
  os << indent << "Mapper: " << this->Mapper << "\n";
  if (this->Mapper) this->Mapper->PrintSelf(os, indent.GetNextIndent());
90
91
}

92
// Description:
Ken Martin's avatar
Ken Martin committed
93
// Set the actor2D's position in display coordinates.  
94
95
void vtkActor2D::SetDisplayPosition(int XPos, int YPos)
{
Ken Martin's avatar
Ken Martin committed
96
97
  this->PositionCoordinate->SetCoordinateSystem(VTK_DISPLAY);
  this->PositionCoordinate->SetValue((float)XPos,(float)YPos,0.0);
98
99
}

100
101
// Description:
// Renders an actor2D's property and then it's mapper.
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
void vtkActor2D::Render (vtkViewport* viewport)
{
  vtkDebugMacro(<< "vtkActor2D::Render");

  if (!this->Property)
    {
    vtkDebugMacro(<< "vtkActor2D::Render - Creating Property2D");
    // Force creation of default property
    this->GetProperty();
    }

  this->Property->Render(viewport);

  if (!this->Mapper) 
    {
    vtkErrorMacro(<< "vtkActor2D::Render - No mapper set");
    return;
    }

  vtkDebugMacro(<<"vtkActor2D::Render - Rendering mapper");
  this->Mapper->Render(viewport, this); 

}

126
127
128
// Description:
// Returns an actor2D's property2D.  Creates a property if one
// doesn't already exist.
129
130
131
132
133
134
135
136
137
138
139
140
vtkProperty2D *vtkActor2D::GetProperty()
{
  if (this->Property == NULL)
    {
    this->Property = vtkProperty2D::New();
    this->SelfCreatedProperty = 1;
    this->Modified();
    }
  return this->Property;
}


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
unsigned long int vtkActor2D::GetMTime()
{
  unsigned long mTime=this->vtkObject::GetMTime();
  unsigned long time;
  
  time = this->PositionCoordinate->GetMTime();
  mTime = ( time > mTime ? time : mTime );
  
  if ( this->Property != NULL )
    {
    time = this->Property->GetMTime();
    mTime = ( time > mTime ? time : mTime );
    }

  return mTime;
}
157
158
159
160