VMTK
Loading...
Searching...
No Matches
vtkvmtkSimpleCapPolyData.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkSimpleCapPolyData.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:53:14 $
7Version: $Revision: 1.6 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
24#include "vtkIdList.h"
25#include "vtkNew.h"
26#include "vtkPolyData.h"
27#include "vtkCellArray.h"
28#include "vtkPointData.h"
29#include "vtkCellData.h"
30#include "vtkPolyLine.h"
31#include "vtkIdTypeArray.h"
32#include "vtkIntArray.h"
33#include "vtkInformation.h"
34#include "vtkInformationVector.h"
35#include "vtkObjectFactory.h"
36#include "vtkVersion.h"
37
38
40
50
52{
53 if (this->CellEntityIdsArrayName)
54 {
55 delete[] this->CellEntityIdsArrayName;
56 this->CellEntityIdsArrayName = NULL;
57 }
58
59 if (this->BoundaryIds)
60 {
61 this->BoundaryIds->Delete();
62 this->BoundaryIds = NULL;
63 }
64
67
68 if (this->BoundaryCellEntityIds)
69 {
70 this->BoundaryCellEntityIds->Delete();
71 this->BoundaryCellEntityIds = NULL;
72 }
73}
74
76 vtkInformation *vtkNotUsed(request),
77 vtkInformationVector **inputVector,
78 vtkInformationVector *outputVector)
79{
80 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
81 vtkInformation *outInfo = outputVector->GetInformationObject(0);
82
83 vtkPolyData *input = vtkPolyData::SafeDownCast(
84 inInfo->Get(vtkDataObject::DATA_OBJECT()));
85 vtkPolyData *output = vtkPolyData::SafeDownCast(
86 outInfo->Get(vtkDataObject::DATA_OBJECT()));
87
88 if ( input->GetNumberOfPoints() < 1 )
89 {
90 return 1;
91 }
92
93 bool markCells = this->CellEntityIdsArrayName && this->CellEntityIdsArrayName[0];
94
95 input->BuildLinks();
96
97 vtkPoints* newPoints = vtkPoints::New();
98 newPoints->DeepCopy(input->GetPoints());
99
100 vtkCellArray* newPolys = vtkCellArray::New();
101 newPolys->DeepCopy(input->GetPolys());
102
103 vtkIdTypeArray* cellEntityIdsArray = NULL;
104
105 if (markCells)
106 {
107 cellEntityIdsArray = vtkIdTypeArray::New();
108 cellEntityIdsArray->SetName(this->CellEntityIdsArrayName);
109 if (input->GetCellData()->GetArray(this->CellEntityIdsArrayName))
110 {
111 cellEntityIdsArray->DeepCopy(input->GetCellData()->GetArray(this->CellEntityIdsArrayName));
112 }
113 else
114 {
115 cellEntityIdsArray->SetNumberOfTuples(newPolys->GetNumberOfCells());
116 cellEntityIdsArray->FillComponent(0,static_cast<double>(this->CellEntityIdOffset));
117 }
118 }
119
120 // The boundaries either come from the labels the input already carries, which are the same
121 // boundaries in the same order every other filter reading those labels sees, or they are
122 // extracted here as they always were.
123 vtkNew<vtkPolyData> boundaries;
124 vtkNew<vtkIdList> boundaryLabels;
125 bool useBoundaryLabels = vtkvmtkBoundaryLabels::GetOrExtractBoundaries(
126 input,this->BoundaryLabelsArrayName,this->BoundaryPointOrderArrayName,boundaries,boundaryLabels,this);
127
128 for (int i=0; i<boundaries->GetNumberOfCells(); i++)
129 {
130 // A boundary is named by its label when the labels are in use, and by its position in the
131 // extraction order otherwise, here as everywhere else in this filter.
132 vtkIdType boundaryId = useBoundaryLabels ? boundaryLabels->GetId(i) : i;
133 if (this->BoundaryIds)
134 {
135 if (this->BoundaryIds->IsId(boundaryId) == -1)
136 {
137 continue;
138 }
139 }
140 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(i));
141 vtkIdType numberOfBoundaryPoints = boundary->GetNumberOfPoints();
142 vtkIdList* boundaryPointIds = vtkIdList::New();
143 boundaryPointIds->SetNumberOfIds(numberOfBoundaryPoints);
144 for (int j=0; j<numberOfBoundaryPoints; j++)
145 {
146 boundaryPointIds->SetId(j,static_cast<vtkIdType>(boundaries->GetPointData()->GetScalars()->GetTuple1(boundary->GetPointId(j))));
147 }
148 newPolys->InsertNextCell(boundaryPointIds);
149 if (markCells)
150 {
151 // An id the caller chose for this boundary is used as it stands; CellEntityIdOffset is
152 // what moves the ids this filter derives itself out of the way of the input's, and has
153 // no business shifting one that was picked deliberately.
154 // With the labels in use the boundary's label is its name, so it is also the cap's id
155 // unless the caller chose another; neither is shifted by CellEntityIdOffset.
156 vtkIdType capCellEntityId = useBoundaryLabels ? boundaryId : i+1+this->CellEntityIdOffset;
157 if (this->BoundaryCellEntityIds
158 && boundaryId < this->BoundaryCellEntityIds->GetNumberOfTuples()
159 && this->BoundaryCellEntityIds->GetValue(boundaryId) >= 0)
160 {
161 capCellEntityId = this->BoundaryCellEntityIds->GetValue(boundaryId);
162 }
163 cellEntityIdsArray->InsertNextValue(capCellEntityId);
164 }
165 boundaryPointIds->Delete();
166 }
167
168 output->SetPoints(newPoints);
169 output->SetPolys(newPolys);
170
171 output->GetPointData()->PassData(input->GetPointData());
172
173 if (markCells)
174 {
175 output->GetCellData()->AddArray(cellEntityIdsArray);
176 cellEntityIdsArray->Delete();
177 }
178
179 newPoints->Delete();
180 newPolys->Delete();
181
182 return 1;
183}
184
185void vtkvmtkSimpleCapPolyData::PrintSelf(std::ostream& os, vtkIndent indent)
186{
187 this->Superclass::PrintSelf(os,indent);
188}
static bool GetOrExtractBoundaries(vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName, vtkPolyData *boundaries, vtkIdList *boundaryLabels, vtkObject *warningSource=nullptr)
Close holes in a surface by filling each boundary loop with a single flat polygon.
virtual void SetBoundaryPointOrderArrayName(const char *)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
virtual void SetBoundaryLabelsArrayName(const char *)
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkSimpleCapPolyData)