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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkActor2D.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/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 notice for more information.
=========================================================================*/
#include "vtkActor2D.h"
#include "vtkProperty2D.h"
#include "vtkMapper2D.h"
#include "vtkPropCollection.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
vtkStandardNewMacro(vtkActor2D);
vtkCxxSetObjectMacro(vtkActor2D,Property, vtkProperty2D);
vtkCxxSetObjectMacro(vtkActor2D,Mapper, vtkMapper2D);
//----------------------------------------------------------------------------
// Creates an actor2D with the following defaults:
// position -1, -1 (view coordinates)
// orientation 0, scale (1,1), layer 0, visibility on
vtkActor2D::vtkActor2D()
{
this->Mapper = NULL;
this->LayerNumber = 0;
this->Property = NULL;
//
this->PositionCoordinate = vtkCoordinate::New();
this->PositionCoordinate->SetCoordinateSystem(VTK_VIEWPORT);
//
this->Position2Coordinate = vtkCoordinate::New();
this->Position2Coordinate->SetCoordinateSystemToNormalizedViewport();
this->Position2Coordinate->SetValue(0.5, 0.5);
this->Position2Coordinate->SetReferenceCoordinate(this->PositionCoordinate);
}
//----------------------------------------------------------------------------
// Destroy an actor2D.
vtkActor2D::~vtkActor2D()
{
if (this->Property)
{
this->Property->UnRegister(this);
this->Property = NULL;
}
if (this->PositionCoordinate)
{
this->PositionCoordinate->Delete();
this->PositionCoordinate = NULL;
}
if (this->Position2Coordinate)
{
this->Position2Coordinate->Delete();
this->Position2Coordinate = NULL;
}
if (this->Mapper != NULL)
{
this->Mapper->UnRegister(this);
this->Mapper = NULL;
}
}
//----------------------------------------------------------------------------
void vtkActor2D::ReleaseGraphicsResources(vtkWindow *win)
{
// pass this information onto the mapper
if (this->Mapper)
{
this->Mapper->ReleaseGraphicsResources(win);
}
}
//----------------------------------------------------------------------------
// Renders an actor2D's property and then it's mapper.
int vtkActor2D::RenderOverlay(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::RenderOverlay");
// Is the viewport's RenderWindow capturing GL2PS-special prop, and does this
// actor represent text or mathtext?
if (vtkRenderer *renderer = vtkRenderer::SafeDownCast(viewport))
{
if (vtkRenderWindow *renderWindow = renderer->GetRenderWindow())
{
if (renderWindow->GetCapturingGL2PSSpecialProps())
{
if (this->IsA("vtkTextActor") ||
(this->Mapper && (this->Mapper->IsA("vtkTextMapper") ||
this->Mapper->IsA("vtkLabeledDataMapper"))))
{
renderer->CaptureGL2PSSpecialProp(this);
}
}
}
}
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 0;
}
this->Mapper->RenderOverlay(viewport, this);
return 1;
}
//----------------------------------------------------------------------------
// Renders an actor2D's property and then it's mapper.
int vtkActor2D::RenderOpaqueGeometry(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::RenderOpaqueGeometry");
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 0;
}
this->Mapper->RenderOpaqueGeometry(viewport, this);
return 1;
}
//-----------------------------------------------------------------------------
// Renders an actor2D's property and then it's mapper.
int vtkActor2D::RenderTranslucentPolygonalGeometry(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::RenderTranslucentPolygonalGeometry");
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 0;
}
this->Mapper->RenderTranslucentPolygonalGeometry(viewport, this);
return 1;
}
//-----------------------------------------------------------------------------
int vtkActor2D::HasTranslucentPolygonalGeometry()
{
int result;
if(this->Mapper)
{
result=this->Mapper->HasTranslucentPolygonalGeometry();
}
else
{
vtkErrorMacro(<< "vtkActor2D::HasTranslucentPolygonalGeometry - No mapper set");
result=0;
}
return result;
}
//----------------------------------------------------------------------------
unsigned long int vtkActor2D::GetMTime()
{
unsigned long mTime = this->Superclass::GetMTime();
unsigned long time;
time = this->PositionCoordinate->GetMTime();
mTime = ( time > mTime ? time : mTime );
time = this->Position2Coordinate->GetMTime();
mTime = ( time > mTime ? time : mTime );
if ( this->Property != NULL )
{
time = this->Property->GetMTime();
mTime = ( time > mTime ? time : mTime );
}
return mTime;
}
//----------------------------------------------------------------------------
// Set the Prop2D's position in display coordinates.
void vtkActor2D::SetDisplayPosition(int XPos, int YPos)
{
this->PositionCoordinate->SetCoordinateSystem(VTK_DISPLAY);
this->PositionCoordinate->SetValue(static_cast<float>(XPos),
static_cast<float>(YPos),0.0);
}
//----------------------------------------------------------------------------
void vtkActor2D::SetWidth(double w)
{
double *pos;
pos = this->Position2Coordinate->GetValue();
this->Position2Coordinate->SetCoordinateSystemToNormalizedViewport();
this->Position2Coordinate->SetValue(w,pos[1]);
}
//----------------------------------------------------------------------------
void vtkActor2D::SetHeight(double w)
{
double *pos;
pos = this->Position2Coordinate->GetValue();
this->Position2Coordinate->SetCoordinateSystemToNormalizedViewport();
this->Position2Coordinate->SetValue(pos[0],w);
}
//----------------------------------------------------------------------------
double vtkActor2D::GetWidth()
{
return this->Position2Coordinate->GetValue()[0];
}
//----------------------------------------------------------------------------
double vtkActor2D::GetHeight()
{
return this->Position2Coordinate->GetValue()[1];
}
//----------------------------------------------------------------------------
// Returns an Prop2D's property2D. Creates a property if one
// doesn't already exist.
vtkProperty2D *vtkActor2D::GetProperty()
{
if (this->Property == NULL)
{
this->Property = vtkProperty2D::New();
this->Property->Register(this);
this->Property->Delete();
this->Modified();
}
return this->Property;
}
//----------------------------------------------------------------------------
void vtkActor2D::GetActors2D(vtkPropCollection *ac)
{
ac->AddItem(this);
}
//----------------------------------------------------------------------------
void vtkActor2D::ShallowCopy(vtkProp *prop)
{
vtkActor2D *a = vtkActor2D::SafeDownCast(prop);
if ( a != NULL )
{
this->SetMapper(a->GetMapper());
this->SetLayerNumber(a->GetLayerNumber());
this->SetProperty(a->GetProperty());
this->SetPosition(a->GetPosition());
this->SetPosition2(a->GetPosition2());
}
// Now do superclass
this->vtkProp::ShallowCopy(prop);
}
//----------------------------------------------------------------------------
void vtkActor2D::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Layer Number: " << this->LayerNumber << "\n";
os << indent << "PositionCoordinate: " << this->PositionCoordinate << "\n";
this->PositionCoordinate->PrintSelf(os, indent.GetNextIndent());
os << indent << "Position2 Coordinate: " << this->Position2Coordinate << "\n";
this->Position2Coordinate->PrintSelf(os, indent.GetNextIndent());
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());
}
}
|