VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyBall.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyBall.cxx,v $
5Language: C++
6Date: $Date: 2005/03/04 11:07:28 $
7Version: $Revision: 1.2 $
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#include "vtkvmtkPolyBall.h"
22#include "vtkvmtkConstants.h"
23#include "vtkPointData.h"
24#include "vtkObjectFactory.h"
25
26
28
30{
31 this->Input = NULL;
32 this->PolyBallRadiusArrayName = NULL;
33 this->LastPolyBallCenterId = -1;
34}
35
37{
38 if (this->Input)
39 {
40 this->Input->Delete();
41 this->Input = NULL;
42 }
43
45 {
46 delete[] this->PolyBallRadiusArrayName;
47 this->PolyBallRadiusArrayName = NULL;
48 }
49}
50
52{
53 double px[3], pr;
54 int i;
55 double sphereFunctionValue, minSphereFunctionValue;
56 vtkDataArray* polyballRadiusArray;
57
58 if (!this->Input)
59 {
60 vtkErrorMacro("No Input specified!");
61 return 0.0;
62 }
63
64 if (this->Input->GetNumberOfPoints()==0)
65 {
66 vtkWarningMacro("Empty Input specified!");
67 }
68
69 if (!this->PolyBallRadiusArrayName)
70 {
71 vtkErrorMacro("No PolyBallRadiusArrayName specified!");
72 return 0.0;
73 }
74
75 if (!this->Input->GetPointData()->GetArray(this->PolyBallRadiusArrayName))
76 {
77 vtkErrorMacro("PolyBallRadiusArray with name specified does not exist!");
78 return 0.0;
79 }
80
81 polyballRadiusArray = this->Input->GetPointData()->GetArray(this->PolyBallRadiusArrayName);
82 minSphereFunctionValue = VTK_VMTK_LARGE_DOUBLE;
83 for (i=0; i<this->Input->GetNumberOfPoints(); i++)
84 {
85 // this next line actually copies the xyz location of point i into px[3].
86 // luca reports that odd bug happened when only retrieving pointers.
87 this->Input->GetPoint(i,px);
88 pr = polyballRadiusArray->GetComponent(i,0);
89 // x, y, z -> location of query point in R3
90 // px, py, pz => location of point with sphere radius == pr
91 // f = ((x - px)^2 + (y - py)^2 + (z - pz)^2) - pr^2
92 sphereFunctionValue = ((x[0] - px[0]) * (x[0] - px[0]) + (x[1] - px[1]) * (x[1] - px[1]) + (x[2] - px[2]) * (x[2] - px[2])) - pr*pr;
93 if (sphereFunctionValue - minSphereFunctionValue < VTK_VMTK_DOUBLE_TOL)
94 {
95 minSphereFunctionValue = sphereFunctionValue;
96 this->LastPolyBallCenterId = i;
97 }
98 }
99
100 return minSphereFunctionValue;
101}
102
103void vtkvmtkPolyBall::EvaluateGradient(double x[3], double n[3])
104{
105 vtkWarningMacro("Poly ball gradient computation not implemented yet!");
106
107 // TODO
108 // n[0] = 2.0 * (x[0] - this->Center[0]);
109 // n[1] = 2.0 * (x[1] - this->Center[1]);
110 // n[2] = 2.0 * (x[2] - this->Center[2]);
111}
112
113void vtkvmtkPolyBall::PrintSelf(std::ostream& os, vtkIndent indent)
114{
115 this->Superclass::PrintSelf(os,indent);
116
117}
Implements vtkImplicitFunction to evaluate the minimum sphere function from a collection of points wi...
vtkPolyData * Input
double EvaluateFunction(double x[3]) override
void EvaluateGradient(double x[3], double n[3]) override
char * PolyBallRadiusArrayName
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkIdType LastPolyBallCenterId
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyBall)