File: vtkImplicitVolume.cxx

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (164 lines) | stat: -rw-r--r-- 4,507 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

#include "vtkImplicitVolume.h"

#include "vtkDoubleArray.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkVoxel.h"

VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkImplicitVolume);
vtkCxxSetObjectMacro(vtkImplicitVolume, Volume, vtkImageData);

//------------------------------------------------------------------------------
// Construct an vtkImplicitVolume with no initial volume; the OutValue
// set to a large negative number; and the OutGradient set to (0,0,1).
vtkImplicitVolume::vtkImplicitVolume()
{
  this->Volume = nullptr;
  this->OutValue = VTK_DOUBLE_MIN;

  this->OutGradient[0] = 0.0;
  this->OutGradient[1] = 0.0;
  this->OutGradient[2] = 1.0;

  this->PointIds = vtkIdList::New();
  this->PointIds->Allocate(8);
}

//------------------------------------------------------------------------------
vtkImplicitVolume::~vtkImplicitVolume()
{
  if (this->Volume)
  {
    this->Volume->Delete();
    this->Volume = nullptr;
  }
  this->PointIds->Delete();
}

//------------------------------------------------------------------------------
// Evaluate the ImplicitVolume. This returns the interpolated scalar value
// at x[3].
double vtkImplicitVolume::EvaluateFunction(double x[3])
{
  vtkDataArray* scalars;
  int ijk[3];
  vtkIdType numPts, i;
  double pcoords[3], weights[8], s;

  // See if a volume is defined
  if (!this->Volume || !(scalars = this->Volume->GetPointData()->GetScalars()))
  {
    vtkErrorMacro(
      << "Can't evaluate function: either volume is missing or volume has no point data");
    return this->OutValue;
  }

  // Find the cell that contains xyz and get it
  if (this->Volume->ComputeStructuredCoordinates(x, ijk, pcoords))
  {
    this->Volume->GetCellPoints(this->Volume->ComputeCellId(ijk), this->PointIds);
    vtkVoxel::InterpolationFunctions(pcoords, weights);

    numPts = this->PointIds->GetNumberOfIds();
    for (s = 0.0, i = 0; i < numPts; i++)
    {
      s += scalars->GetComponent(this->PointIds->GetId(i), 0) * weights[i];
    }
    return s;
  }
  else
  {
    return this->OutValue;
  }
}

//------------------------------------------------------------------------------
vtkMTimeType vtkImplicitVolume::GetMTime()
{
  vtkMTimeType mTime = this->vtkImplicitFunction::GetMTime();
  vtkMTimeType volumeMTime;

  if (this->Volume != nullptr)
  {
    volumeMTime = this->Volume->GetMTime();
    mTime = (volumeMTime > mTime ? volumeMTime : mTime);
  }

  return mTime;
}

//------------------------------------------------------------------------------
// Evaluate ImplicitVolume gradient.
void vtkImplicitVolume::EvaluateGradient(double x[3], double n[3])
{
  vtkDataArray* scalars;
  int i, ijk[3];
  double pcoords[3], weights[8], *v;
  vtkDoubleArray* gradient;

  // See if a volume is defined
  if (!this->Volume || !(scalars = this->Volume->GetPointData()->GetScalars()))
  {
    vtkErrorMacro(
      << "Can't evaluate gradient: either volume is missing or volume has no point data");
    for (i = 0; i < 3; i++)
    {
      n[i] = this->OutGradient[i];
    }
    return;
  }

  gradient = vtkDoubleArray::New();
  gradient->SetNumberOfComponents(3);
  gradient->SetNumberOfTuples(8);

  // Find the cell that contains xyz and get it
  if (this->Volume->ComputeStructuredCoordinates(x, ijk, pcoords))
  {
    vtkVoxel::InterpolationFunctions(pcoords, weights);
    this->Volume->GetVoxelGradient(ijk[0], ijk[1], ijk[2], scalars, gradient);

    n[0] = n[1] = n[2] = 0.0;
    for (i = 0; i < 8; i++)
    {
      v = gradient->GetTuple(i);
      n[0] += v[0] * weights[i];
      n[1] += v[1] * weights[i];
      n[2] += v[2] * weights[i];
    }
  }

  else
  { // use outside value
    for (i = 0; i < 3; i++)
    {
      n[i] = this->OutGradient[i];
    }
  }
  gradient->Delete();
}

//------------------------------------------------------------------------------
void vtkImplicitVolume::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "Out Value: " << this->GetOutValue() << "\n";
  os << indent << "Out Gradient: (" << this->GetOutGradient()[0] << ", "
     << this->GetOutGradient()[1] << ", " << this->GetOutGradient()[2] << ")\n";

  if (this->GetVolume())
  {
    os << indent << "Volume: " << this->GetVolume() << "\n";
  }
  else
  {
    os << indent << "Volume: (none)\n";
  }
}
VTK_ABI_NAMESPACE_END