| 140 | } |
| 141 | |
| 142 | void vtkEncodedGradientEstimator::Update() |
| 143 | { |
| 144 | int scalarInputSize[3]; |
| 145 | double scalarInputAspect[3]; |
| 146 | double startSeconds, endSeconds; |
| 147 | double startCPUSeconds, endCPUSeconds; |
| 148 | |
| 149 | if (!this->InputData) |
| 150 | { |
| 151 | vtkErrorMacro(<< "No input in gradient estimator."); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | if (this->GetMTime() > this->BuildTime || this->DirectionEncoder->GetMTime() > this->BuildTime || |
| 156 | this->InputData->GetMTime() > this->BuildTime || !this->EncodedNormals) |
| 157 | { |
| 158 | |
| 159 | startSeconds = vtkTimerLog::GetUniversalTime(); |
| 160 | startCPUSeconds = vtkTimerLog::GetCPUTime(); |
| 161 | |
| 162 | // Get the dimensions of the data and its aspect ratio |
| 163 | this->InputData->GetDimensions(scalarInputSize); |
| 164 | this->InputData->GetSpacing(scalarInputAspect); |
| 165 | |
| 166 | // If we previously have allocated space for the encoded normals, |
| 167 | // and this space is no longer the right size, delete it |
| 168 | if (this->EncodedNormalsSize[0] != scalarInputSize[0] || |
| 169 | this->EncodedNormalsSize[1] != scalarInputSize[1] || |
| 170 | this->EncodedNormalsSize[2] != scalarInputSize[2]) |
| 171 | { |
| 172 | delete[] this->EncodedNormals; |
| 173 | this->EncodedNormals = nullptr; |
| 174 | |
| 175 | delete[] this->GradientMagnitudes; |
| 176 | this->GradientMagnitudes = nullptr; |
| 177 | } |
| 178 | |
| 179 | // Compute the number of encoded voxels |
| 180 | vtkIdType encodedSize = scalarInputSize[0]; |
| 181 | encodedSize *= scalarInputSize[1]; |
| 182 | encodedSize *= scalarInputSize[2]; |
| 183 | |
| 184 | // Allocate space for the encoded normals if necessary |
| 185 | if (!this->EncodedNormals) |
| 186 | { |
| 187 | this->EncodedNormals = new unsigned short[encodedSize]; |
| 188 | this->EncodedNormalsSize[0] = scalarInputSize[0]; |
| 189 | this->EncodedNormalsSize[1] = scalarInputSize[1]; |
| 190 | this->EncodedNormalsSize[2] = scalarInputSize[2]; |
| 191 | } |
| 192 | |
| 193 | if (!this->GradientMagnitudes && this->ComputeGradientMagnitudes) |
| 194 | { |
| 195 | this->GradientMagnitudes = new unsigned char[encodedSize]; |
| 196 | } |
| 197 | |
| 198 | // Copy info that multi threaded function will need into temp variables |
| 199 | memcpy(this->InputSize, scalarInputSize, 3 * sizeof(int)); |
no test coverage detected