VMTK
Loading...
Searching...
No Matches
vtkvmtkSparseMatrixRow Class Reference

Represents a single row of a vtkvmtkSparseMatrix: a sparse list of (column id, value) pairs plus a separate diagonal element. More...

#include <vtkvmtkSparseMatrixRow.h>

Inheritance diagram for vtkvmtkSparseMatrixRow:
[legend]
Collaboration diagram for vtkvmtkSparseMatrixRow:
[legend]

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkSparseMatrixRow * NewInstance () const
vtkIdType GetElementIndex (vtkIdType id)
void Initialize ()
void CopyStencil (vtkvmtkStencil *stencil)
void CopyNeighborhood (vtkvmtkNeighborhood *neighborhood)
void DeepCopy (vtkvmtkSparseMatrixRow *src)
vtkIdType GetElementId (vtkIdType i)
void SetElementId (vtkIdType i, vtkIdType id)
double GetElement (vtkIdType i)
void SetElement (vtkIdType i, double element)
vtkIdType GetNumberOfElements ()
void SetNumberOfElements (vtkIdType numberOfElements)
virtual void SetDiagonalElement (double)
virtual double GetDiagonalElement ()

Static Public Member Functions

static vtkvmtkSparseMatrixRow * New ()
static int IsTypeOf (const char *type)
static vtkvmtkSparseMatrixRow * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkSparseMatrixRow ()
 ~vtkvmtkSparseMatrixRow ()

Protected Attributes

vtkIdType * ElementIds
double * Elements
double DiagonalElement
vtkIdType NElements

Detailed Description

Represents a single row of a vtkvmtkSparseMatrix: a sparse list of (column id, value) pairs plus a separate diagonal element.

vtkvmtkSparseMatrixRow stores the off-diagonal, non-zero entries of one matrix row as two parallel arrays – element (column) ids and their values – together with a distinct diagonal value stored separately for fast access. Rows can be populated directly (SetElementId/ SetElement) or built from the neighbor list and weights of a vtkvmtkStencil (CopyStencil) or the point ids of a vtkvmtkNeighborhood (CopyNeighborhood). It is the building block used by vtkvmtkSparseMatrix.

See also
vtkvmtkSparseMatrix, vtkvmtkStencil, vtkvmtkNeighborhood

Definition at line 42 of file vtkvmtkSparseMatrixRow.h.

Member Typedef Documentation

◆ Superclass

Definition at line 47 of file vtkvmtkSparseMatrixRow.h.

Constructor & Destructor Documentation

◆ vtkvmtkSparseMatrixRow()

vtkvmtkSparseMatrixRow::vtkvmtkSparseMatrixRow ( )
protected

Definition at line 29 of file vtkvmtkSparseMatrixRow.cxx.

30{
31 this->NElements = 0;
32 this->ElementIds = NULL;
33 this->Elements = NULL;
34 this->DiagonalElement = 0.0;
35}

◆ ~vtkvmtkSparseMatrixRow()

vtkvmtkSparseMatrixRow::~vtkvmtkSparseMatrixRow ( )
protected

Definition at line 37 of file vtkvmtkSparseMatrixRow.cxx.

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}

Member Function Documentation

◆ New()

vtkvmtkSparseMatrixRow * vtkvmtkSparseMatrixRow::New ( )
static

◆ IsTypeOf()

int vtkvmtkSparseMatrixRow::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkSparseMatrixRow::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkSparseMatrixRow * vtkvmtkSparseMatrixRow::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkSparseMatrixRow::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkSparseMatrixRow * vtkvmtkSparseMatrixRow::NewInstance ( ) const

◆ GetElementId()

vtkIdType vtkvmtkSparseMatrixRow::GetElementId ( vtkIdType i)
inline

Get/set the column id stored at position i (0-based index into this row's element arrays, not a matrix column lookup – see GetElementIndex() to find the position for a given column id).

Definition at line 54 of file vtkvmtkSparseMatrixRow.h.

54{ return this->ElementIds[i]; }

◆ SetElementId()

void vtkvmtkSparseMatrixRow::SetElementId ( vtkIdType i,
vtkIdType id )
inline

Get/set the column id stored at position i (0-based index into this row's element arrays, not a matrix column lookup – see GetElementIndex() to find the position for a given column id).

Definition at line 55 of file vtkvmtkSparseMatrixRow.h.

55{ this->ElementIds[i] = id; }

◆ GetElement()

double vtkvmtkSparseMatrixRow::GetElement ( vtkIdType i)
inline

Get/set the off-diagonal value stored at position i (0-based index into this row's element arrays; see GetElementIndex() to find the position for a given column id).

Definition at line 63 of file vtkvmtkSparseMatrixRow.h.

63{ return this->Elements[i]; }

◆ SetElement()

void vtkvmtkSparseMatrixRow::SetElement ( vtkIdType i,
double element )
inline

Get/set the off-diagonal value stored at position i (0-based index into this row's element arrays; see GetElementIndex() to find the position for a given column id).

Definition at line 64 of file vtkvmtkSparseMatrixRow.h.

64{ this->Elements[i] = element; }

◆ GetElementIndex()

vtkIdType vtkvmtkSparseMatrixRow::GetElementIndex ( vtkIdType id)

Look up the 0-based position within this row's element arrays that holds column id id, by linear search. Returns -1 (and raises an error) if id is not present in the row.

Definition at line 106 of file vtkvmtkSparseMatrixRow.cxx.

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}

◆ GetNumberOfElements()

vtkIdType vtkvmtkSparseMatrixRow::GetNumberOfElements ( )
inline

Get/set the number of off-diagonal (column id, value) entries stored in this row. Setting the count (re)allocates the ElementIds/Elements arrays, releasing any previous contents and filling the new entries with id 0 / value 0.0; the diagonal element is also reset to 0.0.

Definition at line 79 of file vtkvmtkSparseMatrixRow.h.

79{ return this->NElements; }

◆ SetNumberOfElements()

void vtkvmtkSparseMatrixRow::SetNumberOfElements ( vtkIdType numberOfElements)

Get/set the number of off-diagonal (column id, value) entries stored in this row. Setting the count (re)allocates the ElementIds/Elements arrays, releasing any previous contents and filling the new entries with id 0 / value 0.0; the diagonal element is also reset to 0.0.

Definition at line 71 of file vtkvmtkSparseMatrixRow.cxx.

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}

◆ SetDiagonalElement()

virtual void vtkvmtkSparseMatrixRow::SetDiagonalElement ( double )
virtual

Set/get the diagonal value of this matrix row, stored separately from the off-diagonal entries. Default: 0.0.

◆ GetDiagonalElement()

virtual double vtkvmtkSparseMatrixRow::GetDiagonalElement ( )
virtual

Set/get the diagonal value of this matrix row, stored separately from the off-diagonal entries. Default: 0.0.

◆ Initialize()

void vtkvmtkSparseMatrixRow::Initialize ( )

Release the row's element arrays, reset the number of elements to zero, and reset the diagonal element to 0.0.

Definition at line 52 of file vtkvmtkSparseMatrixRow.cxx.

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}

◆ CopyStencil()

void vtkvmtkSparseMatrixRow::CopyStencil ( vtkvmtkStencil * stencil)

Replace this row's contents with the neighbor point ids and weights of stencil: one off-diagonal entry per stencil neighbor (id = stencil point id, value = stencil weight) and the diagonal element set to the stencil's center weight.

Definition at line 126 of file vtkvmtkSparseMatrixRow.cxx.

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}
vtkIdType GetPointId(vtkIdType i)
double GetCenterWeight()
double GetWeight(vtkIdType i)

◆ CopyNeighborhood()

void vtkvmtkSparseMatrixRow::CopyNeighborhood ( vtkvmtkNeighborhood * neighborhood)

Replace this row's off-diagonal column ids with the point ids of neighborhood (one entry per neighbor, values left at 0.0); the diagonal element is left unchanged.

Definition at line 161 of file vtkvmtkSparseMatrixRow.cxx.

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}
void SetNumberOfElements(vtkIdType numberOfElements)

◆ DeepCopy()

void vtkvmtkSparseMatrixRow::DeepCopy ( vtkvmtkSparseMatrixRow * src)

Standard DeepCopy method. Since this object contains no reference to other objects, there is no ShallowCopy.

Definition at line 175 of file vtkvmtkSparseMatrixRow.cxx.

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}

Member Data Documentation

◆ ElementIds

vtkIdType* vtkvmtkSparseMatrixRow::ElementIds
protected

Definition at line 121 of file vtkvmtkSparseMatrixRow.h.

◆ Elements

double* vtkvmtkSparseMatrixRow::Elements
protected

Definition at line 122 of file vtkvmtkSparseMatrixRow.h.

◆ DiagonalElement

double vtkvmtkSparseMatrixRow::DiagonalElement
protected

Definition at line 123 of file vtkvmtkSparseMatrixRow.h.

◆ NElements

vtkIdType vtkvmtkSparseMatrixRow::NElements
protected

Definition at line 124 of file vtkvmtkSparseMatrixRow.h.


The documentation for this class was generated from the following files: