vtkCompositeDataGeometryFilter.cxx 3.73 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   Visualization Toolkit
4
  Module:    vtkCompositeDataGeometryFilter.cxx
5 6 7 8 9 10 11 12 13 14

  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.

=========================================================================*/
15
#include "vtkCompositeDataGeometryFilter.h"
16 17 18 19

#include "vtkAppendPolyData.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
20
#include "vtkCompositeDataSet.h"
21
#include "vtkDataSet.h"
22
#include "vtkDataSetSurfaceFilter.h"
23 24 25
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
26
#include "vtkNew.h"
27
#include "vtkObjectFactory.h"
28
#include "vtkSmartPointer.h"
29

30
vtkStandardNewMacro(vtkCompositeDataGeometryFilter);
31

32
//-----------------------------------------------------------------------------
33
vtkCompositeDataGeometryFilter::vtkCompositeDataGeometryFilter() = default;
34

35
//-----------------------------------------------------------------------------
36
vtkCompositeDataGeometryFilter::~vtkCompositeDataGeometryFilter() = default;
37

38 39
//-----------------------------------------------------------------------------
int vtkCompositeDataGeometryFilter::FillInputPortInformation(
40 41 42
  int vtkNotUsed(port), vtkInformation* info)
{
  // now add our info
43
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
44 45 46
  return 1;
}

47 48
//-----------------------------------------------------------------------------
int vtkCompositeDataGeometryFilter::ProcessRequest(
49 50
  vtkInformation* request,
  vtkInformationVector** inputVector,
51 52 53 54
  vtkInformationVector* outputVector)
{
  // generate the data
  if(request->Has(vtkCompositeDataPipeline::REQUEST_DATA()))
55
  {
56 57
    int retVal = this->RequestCompositeData(request, inputVector, outputVector);
    return retVal;
58
  }
59 60 61 62

 return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}

63 64
//-----------------------------------------------------------------------------
int vtkCompositeDataGeometryFilter::RequestCompositeData(
65 66
  vtkInformation*,
  vtkInformationVector** inputVector,
67 68
  vtkInformationVector*  outputVector)
{
69
  vtkCompositeDataSet* input = vtkCompositeDataSet::GetData(inputVector[0], 0);
70
  if (!input)
71
  {
72 73
    vtkErrorMacro("No input composite dataset provided.");
    return 0;
74
  }
75

76
  vtkPolyData* output = vtkPolyData::GetData(outputVector, 0);
77
  if (!output)
78
  {
79 80
    vtkErrorMacro("No output polydata provided.");
    return 0;
81
  }
82

83 84 85 86
  vtkNew<vtkAppendPolyData> append;
  vtkSmartPointer<vtkCompositeDataIterator> iter;
  iter.TakeReference(input->NewIterator());

87
  for(iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
88
  {
89
    vtkDataSet* ds = vtkDataSet::SafeDownCast(iter->GetCurrentDataObject());
90
    if (ds && ds->GetNumberOfPoints() > 0)
91
    {
92
      vtkNew<vtkDataSetSurfaceFilter> dssf;
93 94
      dssf->SetInputData(ds);
      dssf->Update();
95
      append->AddInputDataObject(dssf->GetOutputDataObject(0));
96
    }
97
  }
98
  if (append->GetNumberOfInputConnections(0) > 0)
99
  {
100 101
    append->Update();
    output->ShallowCopy(append->GetOutput());
102
  }
103 104 105 106

  return 1;
}

107 108
//-----------------------------------------------------------------------------
vtkExecutive* vtkCompositeDataGeometryFilter::CreateDefaultExecutive()
109 110 111 112
{
  return vtkCompositeDataPipeline::New();
}

113 114
//-----------------------------------------------------------------------------
void vtkCompositeDataGeometryFilter::PrintSelf(ostream& os, vtkIndent indent)
115 116 117 118
{
  this->Superclass::PrintSelf(os,indent);
}