VMTK
Loading...
Searching...
No Matches
vtkvmtkStencil.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkStencil.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.5 $
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
22#include "vtkvmtkStencil.h"
23#include "vtkvmtkConstants.h"
24#include "vtkObjectFactory.h"
25#include <cmath>
26
27
28
30 {
31 this->Weights = NULL;
32 this->CenterWeight = NULL;
33 this->NumberOfComponents = 1;
34 this->WeightScaling = 1;
35 this->NegateWeights = 1;
36 }
37
39 {
40 if (this->CenterWeight != NULL)
41 {
42 delete[] this->CenterWeight;
43 this->CenterWeight = NULL;
44 }
45
46 if (this->Weights != NULL)
47 {
48 delete[] this->Weights;
49 this->Weights = NULL;
50 }
51 }
52
54{
55 if (!this->NegateWeights)
56 {
57 return;
58 }
59
60 for (int j=0; j<this->NumberOfComponents*this->NPoints; j++)
61 {
62 this->Weights[j] *= -1.0;
63 }
64}
65
66void vtkvmtkStencil::ResizePointList(vtkIdType ptId, int size)
67 {
68 this->Superclass::ResizePointList(ptId,size);
69
70 double *weights;
71
72 weights = new double[this->NumberOfComponents*this->NPoints];
73 memcpy(weights, this->Weights,this->NumberOfComponents*this->NPoints*sizeof(double));
74 delete [] this->Weights;
75 this->Weights = weights;
76}
77
79 {
80 vtkIdType j;
81
82 if (!this->WeightScaling)
83 {
84 return;
85 }
86
87 if (std::fabs(factor)<VTK_VMTK_DOUBLE_TOL)
88 {
89 for (j=0; j<this->NumberOfComponents*this->NPoints; j++)
90 {
91 this->Weights[j] = 0.0;
92 }
93 for (j=0; j<this->NumberOfComponents; j++)
94 {
95 this->CenterWeight[j] = 0.0;
96 }
97 return;
98 }
99 else if (std::fabs(factor)>VTK_VMTK_LARGE_DOUBLE)
100 {
101 for (j=0; j<this->NumberOfComponents*this->NPoints; j++)
102 {
104 }
105 for (j=0; j<this->NumberOfComponents; j++)
106 {
108 }
109 return;
110 }
111
112 for (j=0; j<this->NumberOfComponents*this->NPoints; j++)
113 {
114 this->Weights[j] *= factor;
115 if (std::fabs(this->Weights[j])<VTK_VMTK_DOUBLE_TOL)
116 {
117 this->Weights[j] = 0.0;
118 }
119 }
120
121 for (j=0; j<this->NumberOfComponents; j++)
122 {
123 this->CenterWeight[j] *= factor;
124 if (std::fabs(this->CenterWeight[j])<VTK_VMTK_DOUBLE_TOL)
125 {
126 this->CenterWeight[j] = 0.0;
127 }
128 }
129
130 }
131
133 {
134 this->Superclass::DeepCopy(src);
135
137
138 if (stencilSrc==NULL)
139 {
140 vtkErrorMacro(<<"Trying to deep copy a non-stencil item");
141 }
142
143 if (this->CenterWeight != NULL)
144 {
145 delete[] this->CenterWeight;
146 this->CenterWeight = NULL;
147 }
148
149 if (this->Weights != NULL)
150 {
151 delete[] this->Weights;
152 this->Weights = NULL;
153 }
154
155 this->NumberOfComponents = stencilSrc->NumberOfComponents;
156
157 if (stencilSrc->NPoints>0)
158 {
159 this->Weights = new double[stencilSrc->NumberOfComponents*stencilSrc->NPoints];
160 memcpy(this->Weights, stencilSrc->Weights, this->NumberOfComponents*this->NPoints * sizeof(double));
161 }
162
163 this->CenterWeight = new double[stencilSrc->NumberOfComponents];
164 memcpy(this->CenterWeight, stencilSrc->CenterWeight, this->NumberOfComponents * sizeof(double));
165
166 this->WeightScaling = stencilSrc->WeightScaling;
167 }
168
virtual void DeepCopy(vtkvmtkItem *src) override
void ResizePointList(vtkIdType ptId, int size)
virtual void DeepCopy(vtkvmtkItem *src) override
vtkIdType NumberOfComponents
double * CenterWeight
static vtkvmtkStencil * SafeDownCast(vtkObjectBase *o)
void ResizePointList(vtkIdType ptId, int size)
void ScaleWeights(double factor)
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE