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
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkDataSetToDataSetFilter.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 "vtkDataSetToDataSetFilter.h"
#include "vtkDemandDrivenPipeline.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPolyData.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkRectilinearGrid.h"
vtkCxxRevisionMacro(vtkDataSetToDataSetFilter, "$Revision: 1.69 $");
// Construct object.
vtkDataSetToDataSetFilter::vtkDataSetToDataSetFilter()
{
this->NumberOfRequiredInputs = 1;
this->SetNumberOfInputPorts(1);
}
vtkDataSetToDataSetFilter::~vtkDataSetToDataSetFilter()
{
}
int vtkDataSetToDataSetFilter::RequestDataObject(vtkInformation*,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo)
{
return 0;
}
vtkDataSet *input = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
if (input)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkDataSet *output = vtkDataSet::SafeDownCast(
info->Get(vtkDataObject::DATA_OBJECT()));
if (!output || !output->IsA(input->GetClassName()))
{
output = input->NewInstance();
output->SetPipelineInformation(info);
output->Delete();
this->GetOutputPortInformation(0)->Set(
vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType());
}
return 1;
}
return 0;
}
int vtkDataSetToDataSetFilter::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// Handling REQUEST_DATA_OBJECT because if the filter is connected
// with SetInputConnection() as opposed to SetInput(), the output
// never gets created
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
{
return this->RequestDataObject(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
// Specify the input data or filter.
void vtkDataSetToDataSetFilter::SetInput(vtkDataSet *input)
{
vtkDataSet *oldInput = this->GetInput();
if (oldInput != NULL)
{
if (input == NULL ||
oldInput->GetDataObjectType() != input->GetDataObjectType())
{
vtkWarningMacro("Changing input type. Deleting output");
this->SetOutput(NULL);
}
}
if (input != NULL && this->vtkSource::GetOutput(0) == NULL)
{
this->vtkSource::SetNthOutput(0, input->NewInstance());
this->Outputs[0]->ReleaseData();
this->Outputs[0]->Delete();
}
this->vtkProcessObject::SetNthInput(0, input);
}
// Get the output of this filter. If output is NULL then input hasn't been set
// which is necessary for abstract objects.
vtkDataSet *vtkDataSetToDataSetFilter::GetOutput()
{
if (this->GetInput() == NULL )
{
vtkErrorMacro(<<"Abstract filters require input to be set before output can be retrieved");
return NULL;
}
// sanity check
if (this->NumberOfOutputs < 1)
{
vtkErrorMacro("Sanity check failed. We should have an output");
return NULL;
}
return (vtkDataSet *)this->Superclass::GetOutput(0);
}
// Get the output as vtkPolyData.
vtkPolyData *vtkDataSetToDataSetFilter::GetPolyDataOutput()
{
vtkDataSet *ds = this->GetOutput();
if (!ds)
{
return NULL;
}
if (ds->GetDataObjectType() == VTK_POLY_DATA)
{
return (vtkPolyData *)ds;
}
return NULL;
}
// Get the output as vtkStructuredPoints.
vtkStructuredPoints *vtkDataSetToDataSetFilter::GetStructuredPointsOutput()
{
vtkDataSet *ds = this->GetOutput();
if (!ds)
{
return NULL;
}
if (ds->GetDataObjectType() == VTK_STRUCTURED_POINTS)
{
return (vtkStructuredPoints *)ds;
}
return NULL;
}
// Get the output as vtkStructuredGrid.
vtkStructuredGrid *vtkDataSetToDataSetFilter::GetStructuredGridOutput()
{
vtkDataSet *ds = this->GetOutput();
if (!ds)
{
return NULL;
}
if (ds->GetDataObjectType() == VTK_STRUCTURED_GRID)
{
return (vtkStructuredGrid *)ds;
}
return NULL;
}
// Get the output as vtkUnstructuredGrid.
vtkUnstructuredGrid *vtkDataSetToDataSetFilter::GetUnstructuredGridOutput()
{
vtkDataSet *ds = this->GetOutput();
if (!ds)
{
return NULL;
}
if (ds->GetDataObjectType() == VTK_UNSTRUCTURED_GRID)
{
return (vtkUnstructuredGrid *)ds;
}
return NULL;
}
// Get the output as vtkRectilinearGrid.
vtkRectilinearGrid *vtkDataSetToDataSetFilter::GetRectilinearGridOutput()
{
vtkDataSet *ds = this->GetOutput();
if (!ds)
{
return NULL;
}
if (ds->GetDataObjectType() == VTK_RECTILINEAR_GRID)
{
return (vtkRectilinearGrid *)ds;
}
return NULL;
}
//----------------------------------------------------------------------------
// Specify the input data or filter.
vtkDataSet *vtkDataSetToDataSetFilter::GetInput()
{
if (this->NumberOfInputs < 1)
{
return NULL;
}
return (vtkDataSet *)(this->Inputs[0]);
}
//----------------------------------------------------------------------------
// We know input and output match in type - call the type specific version of
// copy information
void vtkDataSetToDataSetFilter::ExecuteInformation()
{
vtkDataSet* output = this->GetOutput();
if(output)
{
output->CopyTypeSpecificInformation( this->GetInput() );
}
}
//----------------------------------------------------------------------------
// Copy the update information across
void vtkDataSetToDataSetFilter::ComputeInputUpdateExtents(vtkDataObject *output)
{
vtkDataObject *input = this->GetInput();
input->SetUpdatePiece( output->GetUpdatePiece() );
input->SetUpdateNumberOfPieces( output->GetUpdateNumberOfPieces() );
input->SetUpdateGhostLevel( output->GetUpdateGhostLevel() );
input->SetUpdateExtent( output->GetUpdateExtent() );
input->RequestExactExtentOn();
}
//----------------------------------------------------------------------------
vtkDataSet *vtkDataSetToDataSetFilter::GetOutput(int idx)
{
return (vtkDataSet *) this->vtkDataSetSource::GetOutput(idx);
}
//----------------------------------------------------------------------------
int
vtkDataSetToDataSetFilter
::FillInputPortInformation(int port, vtkInformation* info)
{
if(!this->Superclass::FillInputPortInformation(port, info))
{
return 0;
}
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}
//----------------------------------------------------------------------------
void vtkDataSetToDataSetFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|