VMTK
Loading...
Searching...
No Matches
vtkvmtkMeshProjection.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkMeshProjection.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:53:14 $
7Version: $Revision: 1.1 $
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
24#include "vtkCellLocator.h"
25#include "vtkDoubleArray.h"
26#include "vtkGenericCell.h"
27#include "vtkUnstructuredGrid.h"
28#include "vtkPointData.h"
29#include "vtkMath.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33
34
36
38{
39 this->ReferenceMesh = NULL;
40 this->Tolerance = 1E-6;
41}
42
44{
45 if (this->ReferenceMesh)
46 {
47 this->ReferenceMesh->Delete();
48 this->ReferenceMesh = NULL;
49 }
50}
51
53 vtkInformation *vtkNotUsed(request),
54 vtkInformationVector **inputVector,
55 vtkInformationVector *outputVector)
56{
57 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
58 vtkInformation *outInfo = outputVector->GetInformationObject(0);
59
60 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
61 inInfo->Get(vtkDataObject::DATA_OBJECT()));
62 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
63 outInfo->Get(vtkDataObject::DATA_OBJECT()));
64
65 vtkIdType i;
66 vtkIdType cellId;
67 int subId;
68 double point[3], closestPoint[3];
69 double pcoords[3];
70 double distance2;
71 vtkCellLocator *locator;
72 vtkGenericCell *genericCell;
73
74 if (!this->ReferenceMesh)
75 {
76 vtkErrorMacro(<<"No reference mesh!");
77 return 1;
78 }
79
80 int numberOfPoints = input->GetNumberOfPoints();
81
82 output->DeepCopy(input);
83
84 vtkPointData* outputPointData = output->GetPointData();
85 vtkPointData* referencePointData = this->ReferenceMesh->GetPointData();
86
87 outputPointData->InterpolateAllocate(referencePointData,numberOfPoints);
88
89 locator = vtkCellLocator::New();
90 genericCell = vtkGenericCell::New();
91
92 locator->SetDataSet(this->ReferenceMesh);
93 locator->BuildLocator();
94 locator->SetTolerance(this->Tolerance);
95
96 for (i=0; i<numberOfPoints; i++)
97 {
98 input->GetPoint(i,point);
99 locator->FindClosestPoint(point,closestPoint,genericCell,cellId,subId,distance2);
100 double* weights = new double[genericCell->GetNumberOfPoints()];
101 genericCell->EvaluatePosition(closestPoint,NULL,subId,pcoords,distance2,weights);
102
103 outputPointData->InterpolatePoint(referencePointData,i,genericCell->GetPointIds(),weights);
104
105 delete[] weights;
106 }
107
108 locator->Delete();
109 genericCell->Delete();
110
111 return 1;
112}
113
114void vtkvmtkMeshProjection::PrintSelf(std::ostream& os, vtkIndent indent)
115{
116 this->Superclass::PrintSelf(os,indent);
117}
Project point data from a reference mesh onto a query mesh.
vtkUnstructuredGrid * ReferenceMesh
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkMeshProjection)