1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkCountFaces.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #include "vtkCountFaces.h"
17 
18 #include "vtkCellData.h"
19 #include "vtkCellIterator.h"
20 #include "vtkDataSet.h"
21 #include "vtkIdTypeArray.h"
22 #include "vtkInformation.h"
23 #include "vtkInformationVector.h"
24 #include "vtkNew.h"
25 #include "vtkObjectFactory.h"
26 
27 vtkStandardNewMacro(vtkCountFaces);
28 
29 //------------------------------------------------------------------------------
PrintSelf(std::ostream & os,vtkIndent indent)30 void vtkCountFaces::PrintSelf(std::ostream& os, vtkIndent indent)
31 {
32   this->Superclass::PrintSelf(os, indent);
33 
34   os << indent
35      << "OutputArrayName: " << (this->OutputArrayName ? this->OutputArrayName : "(nullptr)")
36      << "\n";
37 }
38 
39 //------------------------------------------------------------------------------
vtkCountFaces()40 vtkCountFaces::vtkCountFaces()
41   : OutputArrayName(nullptr)
42 {
43   this->SetOutputArrayName("Face Count");
44 }
45 
46 //------------------------------------------------------------------------------
~vtkCountFaces()47 vtkCountFaces::~vtkCountFaces()
48 {
49   this->SetOutputArrayName(nullptr);
50 }
51 
52 //------------------------------------------------------------------------------
RequestData(vtkInformation *,vtkInformationVector ** inInfoVec,vtkInformationVector * outInfoVec)53 int vtkCountFaces::RequestData(
54   vtkInformation*, vtkInformationVector** inInfoVec, vtkInformationVector* outInfoVec)
55 {
56   // get the info objects
57   vtkInformation* inInfo = inInfoVec[0]->GetInformationObject(0);
58   vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
59 
60   // get the input and output
61   vtkDataSet* input = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
62   vtkDataSet* output = vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
63 
64   assert(input && output);
65 
66   output->ShallowCopy(input);
67 
68   vtkNew<vtkIdTypeArray> faceCount;
69   faceCount->Allocate(input->GetNumberOfCells());
70   faceCount->SetName(this->OutputArrayName);
71   output->GetCellData()->AddArray(faceCount);
72 
73   vtkCellIterator* it = input->NewCellIterator();
74   for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell())
75   {
76     faceCount->InsertNextValue(it->GetNumberOfFaces());
77   }
78   it->Delete();
79 
80   return 1;
81 }
82 
83 //------------------------------------------------------------------------------
FillOutputPortInformation(int,vtkInformation * info)84 int vtkCountFaces::FillOutputPortInformation(int, vtkInformation* info)
85 {
86   info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataSet");
87   return 1;
88 }
89 
90 //------------------------------------------------------------------------------
FillInputPortInformation(int,vtkInformation * info)91 int vtkCountFaces::FillInputPortInformation(int, vtkInformation* info)
92 {
93   info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
94   return 1;
95 }
96