VMTK
Loading...
Searching...
No Matches
vtkvmtkLinearizeMeshFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkLinearizeMeshFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
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
23#include "vtkUnstructuredGrid.h"
24#include "vtkPoints.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkCellArray.h"
28#include "vtkIdTypeArray.h"
29#include "vtkIdList.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33
34
36
41
45
47 vtkInformation *vtkNotUsed(request),
48 vtkInformationVector **inputVector,
49 vtkInformationVector *outputVector)
50{
51 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
52 vtkInformation *outInfo = outputVector->GetInformationObject(0);
53
54 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
55 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
56
57 vtkPoints* outputPoints = vtkPoints::New();
58
59 vtkCellArray* outputCellArray = vtkCellArray::New();
60 vtkIdList* outputCellTypes = vtkIdList::New();
61
62 int numberOfPoints = input->GetNumberOfPoints();
63 int numberOfCells = input->GetNumberOfCells();
64
65 vtkPointData* inputPointData = input->GetPointData();
66 vtkPointData* outputPointData = output->GetPointData();
67 outputPointData->CopyAllocate(inputPointData,numberOfPoints);
68
69 vtkCellData* inputCellData = input->GetCellData();
70 vtkCellData* outputCellData = output->GetCellData();
71 outputCellData->CopyAllocate(inputCellData,numberOfCells);
72
73 vtkIdTypeArray* pointUsedArray = vtkIdTypeArray::New();
74 pointUsedArray->SetNumberOfTuples(numberOfPoints);
75 pointUsedArray->FillComponent(0,0.0);
76
77 vtkIdList* cellPoints = vtkIdList::New();
78 vtkIdList* outputCellPoints = vtkIdList::New();
79 int pointId;
80 int outputCellId;
81 int i,j;
82 for (i=0; i<numberOfCells; i++)
83 {
84 int cellType = input->GetCellType(i);
85 cellPoints->Initialize();
86 input->GetCellPoints(i,cellPoints);
87 outputCellPoints->Initialize();
88 switch (cellType)
89 {
90 case VTK_TRIANGLE:
91 case VTK_QUADRATIC_TRIANGLE:
92 for (j=0; j<3; j++)
93 {
94 pointId = cellPoints->GetId(j);
95 outputCellPoints->InsertNextId(pointId);
96 pointUsedArray->SetValue(pointId,1);
97 }
98 outputCellId = outputCellTypes->InsertNextId(VTK_TRIANGLE);
99 outputCellArray->InsertNextCell(outputCellPoints);
100 outputCellData->CopyData(inputCellData,i,outputCellId);
101 break;
102 case VTK_QUAD:
103 case VTK_QUADRATIC_QUAD:
104 case VTK_QUADRATIC_LINEAR_QUAD:
105 case VTK_BIQUADRATIC_QUAD:
106 for (j=0; j<4; j++)
107 {
108 pointId = cellPoints->GetId(j);
109 outputCellPoints->InsertNextId(pointId);
110 pointUsedArray->SetValue(pointId,1);
111 }
112 outputCellId = outputCellTypes->InsertNextId(VTK_QUAD);
113 outputCellArray->InsertNextCell(outputCellPoints);
114 outputCellData->CopyData(inputCellData,i,outputCellId);
115 break;
116 case VTK_TETRA:
117 case VTK_QUADRATIC_TETRA:
118 for (j=0; j<4; j++)
119 {
120 pointId = cellPoints->GetId(j);
121 outputCellPoints->InsertNextId(pointId);
122 pointUsedArray->SetValue(pointId,1);
123 }
124 outputCellId = outputCellTypes->InsertNextId(VTK_TETRA);
125 outputCellArray->InsertNextCell(outputCellPoints);
126 outputCellData->CopyData(inputCellData,i,outputCellId);
127 break;
128 case VTK_HEXAHEDRON:
129 case VTK_QUADRATIC_HEXAHEDRON:
130 case VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON:
131 case VTK_TRIQUADRATIC_HEXAHEDRON:
132 for (j=0; j<8; j++)
133 {
134 pointId = cellPoints->GetId(j);
135 outputCellPoints->InsertNextId(pointId);
136 pointUsedArray->SetValue(pointId,1);
137 }
138 outputCellId = outputCellTypes->InsertNextId(VTK_HEXAHEDRON);
139 outputCellArray->InsertNextCell(outputCellPoints);
140 outputCellData->CopyData(inputCellData,i,outputCellId);
141 break;
142 case VTK_WEDGE:
143 case VTK_QUADRATIC_WEDGE:
144 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
145 for (j=0; j<6; j++)
146 {
147 pointId = cellPoints->GetId(j);
148 outputCellPoints->InsertNextId(pointId);
149 pointUsedArray->SetValue(pointId,1);
150 }
151 outputCellId = outputCellTypes->InsertNextId(VTK_WEDGE);
152 outputCellArray->InsertNextCell(outputCellPoints);
153 outputCellData->CopyData(inputCellData,i,outputCellId);
154 break;
155 default:
156 vtkWarningMacro(<<"Unsupported element to linearize. Skipping element.");
157 break;
158 }
159 }
160
161 vtkIdTypeArray* pointIdMapArray = vtkIdTypeArray::New();
162 pointIdMapArray->SetNumberOfTuples(numberOfPoints);
163 for (i=0; i<numberOfPoints; i++)
164 {
165 if (this->CleanOutput)
166 {
167 if (!pointUsedArray->GetValue(i))
168 {
169 continue;
170 }
171 }
172 pointId = outputPoints->InsertNextPoint(input->GetPoint(i));
173 outputPointData->CopyData(inputPointData,i,pointId);
174 pointIdMapArray->SetValue(i,pointId);
175 }
176
177 vtkCellArray* remappedOutputCellArray = vtkCellArray::New();
178 int numberOfOutputCells = outputCellArray->GetNumberOfCells();
179 outputCellArray->InitTraversal();
180 vtkIdType npts = 0;
181 const vtkIdType *pts = NULL;
182 for (i=0; i<numberOfOutputCells; i++)
183 {
184 outputCellArray->GetNextCell(npts,pts);
185 outputCellPoints->Initialize();
186 for (j=0; j<npts; j++)
187 {
188 outputCellPoints->InsertNextId(pointIdMapArray->GetValue(pts[j]));
189 }
190 remappedOutputCellArray->InsertNextCell(outputCellPoints);
191 }
192
193 output->GetPointData()->Squeeze();
194 output->GetCellData()->Squeeze();
195
196 output->SetPoints(outputPoints);
197
198 int* outputCellTypesInt = new int[outputCellTypes->GetNumberOfIds()];
199 for (i=0; i<outputCellTypes->GetNumberOfIds(); i++)
200 {
201 outputCellTypesInt[i] = outputCellTypes->GetId(i);
202 }
203
204 output->SetCells(outputCellTypesInt,remappedOutputCellArray);
205
206 delete[] outputCellTypesInt;
207
208 outputPoints->Delete();
209 outputCellArray->Delete();
210 remappedOutputCellArray->Delete();
211 outputCellTypes->Delete();
212 pointUsedArray->Delete();
213 pointIdMapArray->Delete();
214 cellPoints->Delete();
215 outputCellPoints->Delete();
216
217 return 1;
218}
219
220void vtkvmtkLinearizeMeshFilter::PrintSelf(std::ostream& os, vtkIndent indent)
221{
222 this->Superclass::PrintSelf(os,indent);
223}
Convert quadratic mesh elements to linear mesh elements by discarding mid-side nodes.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkLinearizeMeshFilter)