VMTK
Loading...
Searching...
No Matches
vtkvmtkSparseMatrixRow.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkSparseMatrixRow.cxx,v $
5 Language: C++
6 Date: $Date: 2005/03/04 11:07:30 $
7 Version: $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
23#include "vtkvmtkConstants.h"
24#include "vtkObjectFactory.h"
25
26
28
30{
31 this->NElements = 0;
32 this->ElementIds = NULL;
33 this->Elements = NULL;
34 this->DiagonalElement = 0.0;
35}
36
38{
39 if (this->ElementIds!=NULL)
40 {
41 delete[] this->ElementIds;
42 this->ElementIds = NULL;
43 }
44
45 if (this->Elements!=NULL)
46 {
47 delete[] this->Elements;
48 this->Elements = NULL;
49 }
50}
51
53{
54 this->NElements = 0;
55
56 if (this->ElementIds!=NULL)
57 {
58 delete[] this->ElementIds;
59 this->ElementIds = NULL;
60 }
61
62 if (this->Elements!=NULL)
63 {
64 delete[] this->Elements;
65 this->Elements = NULL;
66 }
67
68 this->DiagonalElement = 0.0;
69}
70
71void vtkvmtkSparseMatrixRow::SetNumberOfElements(vtkIdType numberOfElements)
72{
73 vtkIdType i;
74
75 this->NElements = numberOfElements;
76
77 if (this->ElementIds!=NULL)
78 {
79 delete[] this->ElementIds;
80 this->ElementIds = NULL;
81 }
82
83 this->ElementIds = new vtkIdType[this->NElements];
84
85 for (i=0; i<this->NElements; i++)
86 {
87 this->ElementIds[i] = 0;
88 }
89
90 if (this->Elements!=NULL)
91 {
92 delete[] this->Elements;
93 this->Elements = NULL;
94 }
95
96 this->Elements = new double[this->NElements];
97
98 for (i=0; i<this->NElements; i++)
99 {
100 this->Elements[i] = 0.0;
101 }
102
103 this->DiagonalElement = 0.0;
104}
105
107{
108 vtkIdType index = -1;
109 int j;
110 for (j=0; j<this->NElements; j++)
111 {
112 if (this->ElementIds[j] == id)
113 {
114 index = j;
115 break;
116 }
117 }
118 if (index == -1)
119 {
120 vtkErrorMacro("Error: ElementId not in sparse matrix");
121 return -1;
122 }
123 return index;
124}
125
127{
128 vtkIdType i;
129
130 this->NElements = stencil->GetNumberOfPoints();
131
132 if (this->ElementIds!=NULL)
133 {
134 delete[] this->ElementIds;
135 this->ElementIds = NULL;
136 }
137
138 this->ElementIds = new vtkIdType[this->NElements];
139
140 for (i=0; i<this->NElements; i++)
141 {
142 this->ElementIds[i] = stencil->GetPointId(i);
143 }
144
145 if (this->Elements!=NULL)
146 {
147 delete[] this->Elements;
148 this->Elements = NULL;
149 }
150
151 this->Elements = new double[this->NElements];
152
153 for (i=0; i<this->NElements; i++)
154 {
155 this->Elements[i] = stencil->GetWeight(i);
156 }
157
158 this->DiagonalElement = stencil->GetCenterWeight();
159}
160
162{
163 vtkIdType i;
164
165 int numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
166
167 this->SetNumberOfElements(numberOfNeighborhoodPoints);
168
169 for (i=0; i<numberOfNeighborhoodPoints; i++)
170 {
171 this->ElementIds[i] = neighborhood->GetPointId(i);
172 }
173}
174
176{
177 if (this->ElementIds != NULL)
178 {
179 delete[] this->ElementIds;
180 this->ElementIds = NULL;
181 }
182
183 if (this->Elements != NULL)
184 {
185 delete[] this->Elements;
186 this->Elements = NULL;
187 }
188
189 this->NElements = src->NElements;
190
191 if (src->NElements > 0)
192 {
193 this->ElementIds = new vtkIdType[src->NElements];
194 memcpy(this->ElementIds, src->ElementIds, this->NElements * sizeof(vtkIdType));
195 this->Elements = new double[src->NElements];
196 memcpy(this->Elements, src->Elements, this->NElements * sizeof(double));
197 }
198
199 this->DiagonalElement = src->DiagonalElement;
200}
201
Query the neighborhood surrounding the set point id in an data set item.
vtkIdType GetPointId(vtkIdType i)
Represents a single row of a vtkvmtkSparseMatrix: a sparse list of (column id, value) pairs plus a se...
void SetNumberOfElements(vtkIdType numberOfElements)
void CopyStencil(vtkvmtkStencil *stencil)
vtkIdType GetElementIndex(vtkIdType id)
void DeepCopy(vtkvmtkSparseMatrixRow *src)
void CopyNeighborhood(vtkvmtkNeighborhood *neighborhood)
Serves as an abstract base for a weighting scheme applied to a single point's neighborhood of a data ...
double GetCenterWeight()
double GetWeight(vtkIdType i)
vtkStandardNewMacro(vtkvmtkSparseMatrixRow)