VMTK
Loading...
Searching...
No Matches
vtkvmtkSurfaceProjection.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkSurfaceProjection.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
7Version: $Revision: 1.4 $
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 "vtkPolyData.h"
28#include "vtkPointData.h"
29#include "vtkMath.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33
34
36
41
43{
44 if (this->ReferenceSurface)
45 {
46 this->ReferenceSurface->Delete();
47 this->ReferenceSurface = NULL;
48 }
49}
50
52 vtkInformation *vtkNotUsed(request),
53 vtkInformationVector **inputVector,
54 vtkInformationVector *outputVector)
55{
56 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
57 vtkInformation *outInfo = outputVector->GetInformationObject(0);
58
59 vtkPolyData *input = vtkPolyData::SafeDownCast(
60 inInfo->Get(vtkDataObject::DATA_OBJECT()));
61 vtkPolyData *output = vtkPolyData::SafeDownCast(
62 outInfo->Get(vtkDataObject::DATA_OBJECT()));
63
64 vtkIdType i;
65 vtkIdType cellId;
66 int subId;
67 double point[3], closestPoint[3];
68 double pcoords[3];
69 double distance2;
70 vtkCellLocator *locator;
71 vtkGenericCell *genericCell;
72
73 if (!this->ReferenceSurface)
74 {
75 vtkErrorMacro(<<"No reference surface!");
76 return 1;
77 }
78
79 int numberOfPoints = input->GetNumberOfPoints();
80
81 output->DeepCopy(input);
82
83 vtkPointData* outputPointData = output->GetPointData();
84 vtkPointData* referencePointData = this->ReferenceSurface->GetPointData();
85
86 outputPointData->InterpolateAllocate(referencePointData,numberOfPoints);
87
88 this->ReferenceSurface->BuildCells();
89
90 locator = vtkCellLocator::New();
91 genericCell = vtkGenericCell::New();
92
93 locator->SetDataSet(this->ReferenceSurface);
94 locator->BuildLocator();
95
96 for (i=0; i<numberOfPoints; i++)
97 {
98 input->GetPoint(i,point);
99 locator->FindClosestPoint(point,closestPoint,genericCell,cellId,subId,distance2);
100 if (this->ReferenceSurface->GetCellType(cellId) != VTK_POLY_LINE)
101 {
102 double* weights = new double[genericCell->GetNumberOfPoints()];
103 genericCell->EvaluatePosition(closestPoint,NULL,subId,pcoords,distance2,weights);
104 outputPointData->InterpolatePoint(referencePointData,i,genericCell->GetPointIds(),weights);
105 delete[] weights;
106 }
107 else
108 {
109 double testPoint0[3], testPoint1[3];
110 vtkIdType pointId = genericCell->GetPointId(subId);
111 input->GetPoint(genericCell->GetPointId(subId),testPoint0);
112 input->GetPoint(genericCell->GetPointId(subId+1),testPoint1);
113 if (vtkMath::Distance2BetweenPoints(closestPoint,testPoint1) < vtkMath::Distance2BetweenPoints(closestPoint,testPoint0))
114 {
115 pointId = genericCell->GetPointId(subId+1);
116 }
117 outputPointData->CopyData(referencePointData,pointId,i);
118 }
119 }
120
121 locator->Delete();
122 genericCell->Delete();
123
124 return 1;
125}
126
127void vtkvmtkSurfaceProjection::PrintSelf(std::ostream& os, vtkIndent indent)
128{
129 this->Superclass::PrintSelf(os,indent);
130}
Project point data from a reference surface onto an input surface.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkSurfaceProjection)