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
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkProp.cxx,v $
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 "vtkProp.h"
#include "vtkObjectFactory.h"
#include "vtkAssemblyPaths.h"
#include "vtkCommand.h"
vtkCxxRevisionMacro(vtkProp, "$Revision: 1.25 $");
// Creates an Prop with the following defaults: visibility on.
vtkProp::vtkProp()
{
this->Visibility = 1; // ON
this->Pickable = 1;
this->Dragable = 1;
this->AllocatedRenderTime = 10.0;
this->EstimatedRenderTime = 0.0;
this->RenderTimeMultiplier = 1.0;
this->Paths = NULL;
this->NumberOfConsumers = 0;
this->Consumers = 0;
}
vtkProp::~vtkProp()
{
if ( this->Paths )
{
this->Paths->Delete();
}
if (this->Consumers)
{
delete [] this->Consumers;
}
}
// This method is invoked if the prop is picked.
void vtkProp::Pick()
{
this->InvokeEvent(vtkCommand::PickEvent,NULL);
}
// Shallow copy of vtkProp.
void vtkProp::ShallowCopy(vtkProp *prop)
{
this->Visibility = prop->GetVisibility();
this->Pickable = prop->GetPickable();
this->Dragable = prop->GetDragable();
}
void vtkProp::InitPathTraversal()
{
if ( this->Paths == NULL )
{
this->Paths = vtkAssemblyPaths::New();
vtkAssemblyPath *path = vtkAssemblyPath::New();
path->AddNode(this,NULL);
this->BuildPaths(this->Paths,path);
path->Delete();
}
this->Paths->InitTraversal();
}
vtkAssemblyPath *vtkProp::GetNextPath()
{
if ( ! this->Paths)
{
return NULL;
}
return this->Paths->GetNextItem();
}
// This method is used in conjunction with the assembly object to build a copy
// of the assembly hierarchy. This hierarchy can then be traversed for
// rendering, picking or other operations.
void vtkProp::BuildPaths(vtkAssemblyPaths *paths, vtkAssemblyPath *path)
{
// This is a leaf node in the assembly hierarchy so we
// copy the path in preparation to assingning it to paths.
vtkAssemblyPath *childPath = vtkAssemblyPath::New();
childPath->ShallowCopy(path);
// We can add this path to the list of paths
paths->AddItem(childPath);
childPath->Delete(); //okay, reference counting
}
void vtkProp::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Dragable: " << (this->Dragable ? "On\n" : "Off\n");
os << indent << "Pickable: " << (this->Pickable ? "On\n" : "Off\n");
os << indent << "AllocatedRenderTime: "
<< this->AllocatedRenderTime << endl;
os << indent << "EstimatedRenderTime: "
<< this->EstimatedRenderTime << endl;
os << indent << "NumberOfConsumers: " << this->NumberOfConsumers << endl;
os << indent << "RenderTimeMultiplier: "
<< this->RenderTimeMultiplier << endl;
os << indent << "Visibility: " << (this->Visibility ? "On\n" : "Off\n");
}
void vtkProp::AddConsumer(vtkObject *c)
{
// make sure it isn't already there
if (this->IsConsumer(c))
{
return;
}
// add it to the list, reallocate memory
vtkObject **tmp = this->Consumers;
this->NumberOfConsumers++;
this->Consumers = new vtkObject* [this->NumberOfConsumers];
for (int i = 0; i < (this->NumberOfConsumers-1); i++)
{
this->Consumers[i] = tmp[i];
}
this->Consumers[this->NumberOfConsumers-1] = c;
// free old memory
delete [] tmp;
}
void vtkProp::RemoveConsumer(vtkObject *c)
{
// make sure it is already there
if (!this->IsConsumer(c))
{
return;
}
// remove it from the list, reallocate memory
vtkObject **tmp = this->Consumers;
this->NumberOfConsumers--;
this->Consumers = new vtkObject* [this->NumberOfConsumers];
int cnt = 0;
int i;
for (i = 0; i <= this->NumberOfConsumers; i++)
{
if (tmp[i] != c)
{
this->Consumers[cnt] = tmp[i];
cnt++;
}
}
// free old memory
delete [] tmp;
}
int vtkProp::IsConsumer(vtkObject *c)
{
int i;
for (i = 0; i < this->NumberOfConsumers; i++)
{
if (this->Consumers[i] == c)
{
return 1;
}
}
return 0;
}
vtkObject *vtkProp::GetConsumer(int i)
{
if (i >= this->NumberOfConsumers)
{
return 0;
}
return this->Consumers[i];
}
|