VMTK
Loading...
Searching...
No Matches
vtkvmtkStreamlineToParticlesFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkStreamlineToParticlesFilter.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
23#include "vtkInformation.h"
24#include "vtkInformationVector.h"
25#include "vtkObjectFactory.h"
26#include "vtkVersion.h"
27
28#include "vtkPointData.h"
29#include "vtkMaskPolyData.h"
31#include "vtkIdList.h"
32#include "vtkPolyLine.h"
33#include "vtkDoubleArray.h"
34#include "vtkCellArray.h"
35
36
38
40{
41 this->NumberOfInjections = 10;
43 this->InjectionStart = 0.0;
44 this->InjectionEnd = 1.0;
45 this->TracingEnd = 1.0;
46 this->DeltaT = 1E-2;
47 this->IntegrationTimeArrayName = NULL;
48 this->TimeArrayName = NULL;
49 this->VelocityArrayName = NULL;
50}
51
53{
55 {
56 delete[] this->IntegrationTimeArrayName;
57 this->IntegrationTimeArrayName = NULL;
58 }
59 if (this->TimeArrayName)
60 {
61 delete[] this->TimeArrayName;
62 this->TimeArrayName = NULL;
63 }
64 if (this->VelocityArrayName)
65 {
66 delete[] this->VelocityArrayName;
67 this->VelocityArrayName = NULL;
68 }
69}
70
72 vtkInformation *vtkNotUsed(request),
73 vtkInformationVector **inputVector,
74 vtkInformationVector *outputVector)
75{
76 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
77 vtkInformation *outInfo = outputVector->GetInformationObject(0);
78
79 vtkPolyData *input = vtkPolyData::SafeDownCast(
80 inInfo->Get(vtkDataObject::DATA_OBJECT()));
81 vtkPolyData *output = vtkPolyData::SafeDownCast(
82 outInfo->Get(vtkDataObject::DATA_OBJECT()));
83
84 if (input->GetNumberOfPoints() < 1)
85 {
86 return 1;
87 }
88
89 if (!this->IntegrationTimeArrayName)
90 {
91 vtkErrorMacro("Error: IntegrationTimeArrayName not specified");
92 return 1;
93 }
94
95 vtkDataArray* integrationTimeArray = input->GetPointData()->GetArray(this->IntegrationTimeArrayName);
96
97 if (!integrationTimeArray)
98 {
99 vtkErrorMacro("Error: IntegrationTimeArray with name specified does not exist");
100 return 1;
101 }
102
103 vtkDataArray* velocityArray = NULL;
104
105 if (this->VelocityArrayName)
106 {
107 velocityArray = input->GetPointData()->GetArray(this->VelocityArrayName);
108
109 if (!velocityArray)
110 {
111 vtkErrorMacro("Error: VelocityArray with name specified does not exist");
112 return 1;
113 }
114 }
115
116 int numberOfCells = input->GetNumberOfCells();
117
118 vtkPoints* outputPoints = vtkPoints::New();
119 vtkCellArray* outputVerts = vtkCellArray::New();
120
121 vtkDoubleArray* outputTimeArray = vtkDoubleArray::New();
122 outputTimeArray->SetName(this->TimeArrayName);
123
124 vtkDoubleArray* outputVelocityArray = vtkDoubleArray::New();
125 outputVelocityArray->SetName(this->VelocityArrayName);
126 outputVelocityArray->SetNumberOfComponents(3);
127
128 int i;
129 for (i=0; i<this->NumberOfInjections; i++)
130 {
131 double injectionOffset = this->InjectionStart + i * (this->InjectionEnd - this->InjectionStart) / this->NumberOfInjections;
132
133 vtkMaskPolyData* mask = vtkMaskPolyData::New();
134 mask->SetInputData(input);
135 mask->SetOnRatio(numberOfCells/this->NumberOfParticlesPerInjection);
136 mask->SetOffset(i);
137 mask->Update();
138
139 mask->GetOutput()->GetPointData()->SetActiveScalars(this->IntegrationTimeArrayName);
140
141 vtkPolyData* subset = mask->GetOutput();
142
143 int numberOfSubsetCells = subset->GetNumberOfCells();
144 int j;
145 for (j=0; j<numberOfSubsetCells; j++)
146 {
147 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(subset->GetCell(j));
148 if (!polyLine)
149 {
150 continue;
151 }
152
153 vtkIdList* pointIds = polyLine->GetPointIds();
154 int numberOfPointIds = pointIds->GetNumberOfIds();
155
156 double integrationTime = injectionOffset;
157 int k;
158 for (k=0; k<numberOfPointIds-1; k++)
159 {
160 double time0 = integrationTimeArray->GetTuple1(pointIds->GetId(k));
161 double time1 = integrationTimeArray->GetTuple1(pointIds->GetId(k+1));
162 if (time0 < integrationTime && time1 < integrationTime)
163 {
164 continue;
165 }
166 if (time0 > integrationTime && time1 > integrationTime)
167 {
168 break;
169 }
170 bool valid = true;
171 while (valid)
172 {
173 double pcoord = (integrationTime - time0) / (time1 - time0);
174 double interpolatedPoint[3];
175 vtkvmtkCenterlineUtilities::InterpolatePoint(subset,j,k,pcoord,interpolatedPoint);
176 vtkIdType pointId = outputPoints->InsertNextPoint(interpolatedPoint);
177 outputVerts->InsertNextCell(1);
178 outputVerts->InsertCellPoint(pointId);
179 outputTimeArray->InsertNextValue(integrationTime + injectionOffset);
180 if (velocityArray)
181 {
182 double velocity[3];
184 outputVelocityArray->InsertNextTuple(velocity);
185 }
186 integrationTime += this->DeltaT;
187 if (integrationTime > time1)
188 {
189 valid = false;
190 }
191 if (integrationTime + injectionOffset > this->TracingEnd)
192 {
193 break;
194 }
195 }
196 if (integrationTime + injectionOffset > this->TracingEnd)
197 {
198 break;
199 }
200 }
201 }
202 }
203
204 output->SetPoints(outputPoints);
205 output->SetVerts(outputVerts);
206 output->GetPointData()->AddArray(outputTimeArray);
207 if (velocityArray)
208 {
209 output->GetPointData()->AddArray(outputVelocityArray);
210 }
211
212 outputPoints->Delete();
213 outputVerts->Delete();
214 outputTimeArray->Delete();
215 if (velocityArray)
216 {
217 outputVelocityArray->Delete();
218 }
219
220 return 1;
221}
222
223void vtkvmtkStreamlineToParticlesFilter::PrintSelf(std::ostream& os, vtkIndent indent)
224{
225 this->Superclass::PrintSelf(os,indent);
226}
static void InterpolatePoint(vtkPolyData *centerlines, int cellId, int subId, double pcoord, double interpolatedPoint[3])
static void InterpolateTuple3(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double interpolatedTuple3[3])
Resample time-resolved streamlines into discrete Lagrangian particle positions at successive time ste...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkStreamlineToParticlesFilter)