VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataHarmonicMappingFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataHarmonicMappingFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.7 $
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 "vtkPolyData.h"
24#include "vtkPointData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkDoubleVector.h"
27#include "vtkvmtkStencils.h"
29#include "vtkvmtkSparseMatrix.h"
31#include "vtkvmtkLinearSystem.h"
33
35#include "vtkInformation.h"
36#include "vtkInformationVector.h"
37#include "vtkObjectFactory.h"
38
39
41
52
54{
55 if (this->BoundaryPointIds)
56 {
57 this->BoundaryPointIds->Delete();
58 this->BoundaryPointIds = NULL;
59 }
60
61 if (this->BoundaryValues)
62 {
63 this->BoundaryValues->Delete();
64 this->BoundaryValues = NULL;
65 }
66
68 {
69 delete[] this->HarmonicMappingArrayName;
70 this->HarmonicMappingArrayName = NULL;
71 }
72}
73
75 vtkInformation *vtkNotUsed(request),
76 vtkInformationVector **inputVector,
77 vtkInformationVector *outputVector)
78{
79 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
80 vtkInformation *outInfo = outputVector->GetInformationObject(0);
81
82 vtkPolyData *input = vtkPolyData::SafeDownCast(
83 inInfo->Get(vtkDataObject::DATA_OBJECT()));
84 vtkPolyData *output = vtkPolyData::SafeDownCast(
85 outInfo->Get(vtkDataObject::DATA_OBJECT()));
86
87 if (!this->BoundaryPointIds)
88 {
89 vtkErrorMacro(<<"BoundaryPointIds not set.");
90 return 1;
91 }
92
93 if (!this->BoundaryValues)
94 {
95 vtkErrorMacro(<<"BoundaryValues not set.");
96 return 1;
97 }
98
99 if (!this->HarmonicMappingArrayName)
100 {
101 vtkErrorMacro(<<"HarmonicMappingArrayName not set.");
102 return 1;
103 }
104
105 int numberOfInputPoints = input->GetNumberOfPoints();
106
108
110 rhsVector->SetNormTypeToLInf();
111
113 solutionVector->SetNormTypeToLInf();
114
116 {
119 stencils->WeightScalingOff();
120 stencils->NegateWeightsOn();
121 stencils->SetDataSet(input);
122 stencils->Build();
123
124 sparseMatrix->CopyRowsFromStencils(stencils);
125 rhsVector->Allocate(numberOfInputPoints);
126 rhsVector->Fill(0.0);
127 solutionVector->Allocate(numberOfInputPoints);
128 solutionVector->Fill(0.0);
129
130 stencils->Delete();
131 }
133 {
135 assembler->SetDataSet(input);
136 assembler->SetMatrix(sparseMatrix);
137 assembler->SetRHSVector(rhsVector);
138 assembler->SetSolutionVector(solutionVector);
139 assembler->SetQuadratureOrder(this->QuadratureOrder);
140 assembler->Build();
141 assembler->Delete();
142 }
143
145 linearSystem->SetA(sparseMatrix);
146 linearSystem->SetB(rhsVector);
147 linearSystem->SetX(solutionVector);
148
149 //TODO: deal with NumberOfVariables > 1
151 dirichetBoundaryConditions->SetLinearSystem(linearSystem);
152 dirichetBoundaryConditions->SetBoundaryNodes(this->BoundaryPointIds);
153 dirichetBoundaryConditions->SetBoundaryValues(this->BoundaryValues);
154 dirichetBoundaryConditions->Apply();
155
157 solver->SetLinearSystem(linearSystem);
159 solver->SetMaximumNumberOfIterations(numberOfInputPoints);
160 solver->SetSolverTypeToCG();
162 solver->Solve();
163
164 vtkDoubleArray* harmonicMappingArray = vtkDoubleArray::New();
165 harmonicMappingArray->SetName(this->HarmonicMappingArrayName);
166 harmonicMappingArray->SetNumberOfComponents(1);
167 harmonicMappingArray->SetNumberOfTuples(numberOfInputPoints);
168
169 solutionVector->CopyIntoArrayComponent(harmonicMappingArray,0);
170
171 output->DeepCopy(input);
172
173 output->GetPointData()->AddArray(harmonicMappingArray);
174
175 solver->Delete();
176 harmonicMappingArray->Delete();
177 sparseMatrix->Delete();
178 rhsVector->Delete();
179 solutionVector->Delete();
180 linearSystem->Delete();
181 dirichetBoundaryConditions->Delete();
182
183 return 1;
184}
virtual void SetBoundaryValues(vtkDoubleArray *)
virtual void SetBoundaryNodes(vtkIdList *)
virtual void SetLinearSystem(vtkvmtkLinearSystem *)
void SetDataSet(vtkDataSet *dataSet)
Set up Dirichlet (or first-type) boundary conditions that a linear system needs to take along the bou...
static vtkvmtkDirichletBoundaryConditions * New()
Serves as the base class for vectors utilized in finite-element and other PDE evaluations.
static vtkvmtkDoubleVector * New()
void CopyIntoArrayComponent(vtkDataArray *array, int component)
void Fill(double value)
void Allocate(vtkIdType numberOfElementsPerVariable, vtkIdType numberOfVariables=1)
virtual void SetSolutionVector(vtkvmtkDoubleVector *)
virtual void SetDataSet(vtkDataSet *)
virtual void SetRHSVector(vtkvmtkDoubleVector *)
virtual void SetMatrix(vtkvmtkSparseMatrix *)
virtual void SetQuadratureOrder(int)
virtual void SetConvergenceTolerance(double)
virtual void SetMaximumNumberOfIterations(int)
virtual void SetLinearSystem(vtkvmtkLinearSystem *)
Serves as the base container holding sparse matrix objects that represent a linear system of equation...
virtual void SetX(vtkvmtkDoubleVector *)
virtual void SetA(vtkvmtkSparseMatrix *)
virtual void SetB(vtkvmtkDoubleVector *)
static vtkvmtkLinearSystem * New()
Solve a linear system of equations using open NL.
static vtkvmtkOpenNLLinearSystemSolver * New()
Construct a Laplacian-based finite element calculation on a surface.
static vtkvmtkPolyDataFELaplaceAssembler * New()
Construct a harmonic function over each vascular surface segment used during mapping order to stretch...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Implements a row-based sparse matrix built from mesh neighborhoods or stencils, supporting basic line...
static vtkvmtkSparseMatrix * New()
void CopyRowsFromStencils(vtkvmtkStencils *stencils)
Create an empty, umbrella, area weighted umbrella, finite-element LP, or finite-volume finite-element...
void SetStencilTypeToFELaplaceBeltramiStencil()
virtual void WeightScalingOff()
virtual void NegateWeightsOn()
static vtkvmtkStencils * New()
vtkStandardNewMacro(vtkvmtkPolyDataHarmonicMappingFilter)