VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataSampleFunction.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataSampleFunction.cxx,v $
5 Language: C++
6 Date: $$
7 Version: $$
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 Note: this class was contributed by
21 Tangui Morvan
22 Kalkulo AS
23 Simula Research Laboratory
24=========================================================================*/
25
27
28#include "vtkPointData.h"
29#include "vtkDoubleArray.h"
30#include "vtkMath.h"
31#include "vtkInformation.h"
32#include "vtkInformationVector.h"
33#include "vtkObjectFactory.h"
34#include "vtkIOStream.h"
35
36#include "vtkvmtkConstants.h"
37
38
40vtkCxxSetObjectMacro(vtkvmtkPolyDataSampleFunction,ImplicitFunction,vtkImplicitFunction);
41
47
49{
50 if (this->SampleArrayName)
51 {
52 delete[] this->SampleArrayName;
53 this->SampleArrayName = NULL;
54 }
55
56 this->ImplicitFunction = NULL;
57}
58
59
60
62 vtkInformation *vtkNotUsed(request),
63 vtkInformationVector **inputVector,
64 vtkInformationVector *outputVector)
65{
66 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
67 vtkInformation *outInfo = outputVector->GetInformationObject(0);
68
69 vtkPolyData *input = vtkPolyData::SafeDownCast(
70 inInfo->Get(vtkDataObject::DATA_OBJECT()));
71 vtkPolyData *output = vtkPolyData::SafeDownCast(
72 outInfo->Get(vtkDataObject::DATA_OBJECT()));
73
74 if (!this->SampleArrayName)
75 {
76 vtkErrorMacro(<<"DistanceToSpheresArrayName not set.");
77 return 1;
78 }
79
80 if (!this->ImplicitFunction)
81 {
82 vtkErrorMacro(<<"ImplicitFunction not set.");
83 return 1;
84 }
85
86 int numberOfInputPoints = input->GetNumberOfPoints();
87
88 output->DeepCopy(input);
89
90
91 vtkDataArray* sampleArray = output->GetPointData()->GetArray(this->SampleArrayName);
92
93 bool createArray = !sampleArray;
94
95 if (createArray)
96 {
97 sampleArray = vtkDoubleArray::New();
98 sampleArray->SetName(this->SampleArrayName);
99 sampleArray->SetNumberOfComponents(1);
100 sampleArray->SetNumberOfTuples(numberOfInputPoints);
101 sampleArray->FillComponent(0, 0);
102 output->GetPointData()->AddArray(sampleArray);
103 }
104
105
106
107 double point[3];
108 for (int i=0; i<numberOfInputPoints; i++)
109 {
110 input->GetPoint(i,point);
111 sampleArray->SetComponent(i,0,this->ImplicitFunction->EvaluateFunction(point));
112 }
113
114 if (createArray) sampleArray->Delete();
115
116 return 1;
117}
Sample an implicit function at the points of a surface.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkCxxSetObjectMacro(vtkvmtkPolyDataSampleFunction, ImplicitFunction, vtkImplicitFunction)
vtkStandardNewMacro(vtkvmtkPolyDataSampleFunction)