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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSpatialRepresentationFilter.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 "vtkSpatialRepresentationFilter.h"
#include "vtkLocator.h"
#include "vtkInformation.h"
#include "vtkGarbageCollector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
vtkStandardNewMacro(vtkSpatialRepresentationFilter);
vtkCxxSetObjectMacro(vtkSpatialRepresentationFilter,
SpatialRepresentation,vtkLocator);
vtkSpatialRepresentationFilter::vtkSpatialRepresentationFilter()
{
this->NumberOfRequiredInputs = 1;
this->SetNumberOfInputPorts(1);
this->SpatialRepresentation = NULL;
this->Level = 0;
this->TerminalNodesRequested = 0;
}
vtkSpatialRepresentationFilter::~vtkSpatialRepresentationFilter()
{
if ( this->SpatialRepresentation )
{
this->SpatialRepresentation->UnRegister(this);
this->SpatialRepresentation = NULL;
}
}
vtkPolyData *vtkSpatialRepresentationFilter::GetOutput()
{
if ( !this->TerminalNodesRequested )
{
this->TerminalNodesRequested = 1;
this->Modified();
}
return this->vtkPolyDataSource::GetOutput();
}
vtkPolyData *vtkSpatialRepresentationFilter::GetOutput(int level)
{
if ( level < 0 || !this->SpatialRepresentation ||
level > this->SpatialRepresentation->GetMaxLevel() )
{
vtkErrorMacro(<<"Level requested is <0 or >= Locator's MaxLevel");
return this->GetOutput();
}
if ( this->GetNumberOfOutputs() <= level ||
this->Outputs[level] == NULL )
{
this->vtkSource::SetNthOutput(level, vtkPolyData::New());
this->Modified(); //asking for new output
}
return (vtkPolyData *)(this->Outputs[level]);
}
void vtkSpatialRepresentationFilter::ResetOutput()
{
this->TerminalNodesRequested = 0;
for ( int i=0; i <= VTK_MAX_SPATIAL_REP_LEVEL; i++)
{
this->vtkSource::SetNthOutput(i, NULL);
}
}
// Build OBB tree
void vtkSpatialRepresentationFilter::Execute()
{
vtkDebugMacro(<<"Building OBB representation");
if (this->SpatialRepresentation == NULL)
{
vtkErrorMacro(<< "SpatialRepresentation is NULL.");
return;
}
this->SpatialRepresentation->SetDataSet(this->GetInput());
this->SpatialRepresentation->Update();
this->Level = this->SpatialRepresentation->GetLevel();
vtkDebugMacro(<<"OBB deepest tree level: " << this->Level);
this->GenerateOutput();
}
// Generate OBB representations at different requested levels.
void vtkSpatialRepresentationFilter::GenerateOutput()
{
vtkDataSet *input = this->GetInput();
if (!input)
{
return;
}
vtkPolyData *output;
int inputModified=(input->GetMTime() > this->GetMTime() ? 1 : 0);
int i;
//
// If input to filter is modified, have to update all levels of OBB
//
if ( inputModified )
{
for ( i=0; i <= this->Level; i++ )
{
if ( i < this->NumberOfOutputs && this->Outputs[i] != NULL )
{
output = (vtkPolyData *)(this->Outputs[i]);
output->Initialize();
}
}
}
//
// Loop over all requested levels generating new levels as necessary
//
for ( i=0; i <= this->Level && i < this->NumberOfOutputs; i++ )
{
output = (vtkPolyData *)(this->Outputs[i]);
if ( output != NULL && output->GetNumberOfPoints() < 1 ) //compute OBB
{
this->SpatialRepresentation->GenerateRepresentation(i, output);
}
}
//
// If terminal leafs requested, generate rep
//
if ( this->TerminalNodesRequested )
{
output = this->GetOutput();
this->SpatialRepresentation->GenerateRepresentation(-1, output);
}
}
void vtkSpatialRepresentationFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Level: " << this->Level << "\n";
if ( this->SpatialRepresentation )
{
os << indent << "Spatial Representation: " << this->SpatialRepresentation
<< "\n";
}
else
{
os << indent << "Spatial Representation: (none)\n";
}
}
//----------------------------------------------------------------------------
// Specify the input data or filter.
void vtkSpatialRepresentationFilter::SetInput(vtkDataSet *input)
{
this->vtkProcessObject::SetNthInput(0, input);
}
//----------------------------------------------------------------------------
// Specify the input data or filter.
vtkDataSet *vtkSpatialRepresentationFilter::GetInput()
{
if (this->NumberOfInputs < 1)
{
return NULL;
}
return (vtkDataSet *)(this->Inputs[0]);
}
//----------------------------------------------------------------------------
void vtkSpatialRepresentationFilter::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
// This filter shares our input and is therefore involved in a
// reference loop.
vtkGarbageCollectorReport(collector, this->SpatialRepresentation,
"SpatialRepresentation");
}
//----------------------------------------------------------------------------
int vtkSpatialRepresentationFilter::FillInputPortInformation(int port, vtkInformation* info)
{
if(!this->Superclass::FillInputPortInformation(port, info))
{
return 0;
}
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}
|