Skip to content

Commit

Permalink
Merge pull request #1852 from blowekamp/FixMoreEmptyCompositeTransform
Browse files Browse the repository at this point in the history
BUG: Fix additional segmentation faults with empty Composite - For Release
  • Loading branch information
blowekamp authored Jun 9, 2020
2 parents ecad7ff + 14a8919 commit 6eb2bb0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 120 deletions.
162 changes: 42 additions & 120 deletions Modules/Core/Transform/include/itkCompositeTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformPoint(const Inpu
{

/* Apply in reverse queue order. */
typename TransformQueueType::const_iterator it(this->m_TransformQueue.end());
const typename TransformQueueType::const_iterator beginit(this->m_TransformQueue.begin());
OutputPointType outputPoint(inputPoint);
do
OutputPointType outputPoint(inputPoint);
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != beginit);
}
return outputPoint;
}

Expand All @@ -90,15 +87,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
{
OutputVectorType outputVector(inputVector);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
/* Apply in reverse queue order. */
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -112,16 +106,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
OutputVectorType outputVector(inputVector);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -135,16 +125,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
OutputVnlVectorType outputVector(inputVector);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -156,15 +142,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
{
OutputVnlVectorType outputVector(inputVector);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -176,15 +158,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
{
OutputVectorPixelType outputVector(inputVector);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -198,16 +176,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformVector(const Inp
OutputVectorPixelType outputVector(inputVector);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformVector(outputVector, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -220,15 +194,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformCovariantVector(
{
OutputCovariantVectorType outputVector(inputVector);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformCovariantVector(outputVector);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -243,16 +213,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformCovariantVector(
OutputCovariantVectorType outputVector(inputVector);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformCovariantVector(outputVector, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -265,15 +231,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformCovariantVector(
{
OutputVectorPixelType outputVector(inputVector);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformCovariantVector(outputVector);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -288,16 +250,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformCovariantVector(
OutputVectorPixelType outputVector(inputVector);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputVector = (*it)->TransformCovariantVector(outputVector, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputVector;
}
Expand All @@ -312,16 +270,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformDiffusionTensor3
OutputDiffusionTensor3DType outputTensor(inputTensor);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformDiffusionTensor3D(outputTensor, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -336,16 +290,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformDiffusionTensor3
OutputVectorPixelType outputTensor(inputTensor);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformDiffusionTensor3D(outputTensor, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -358,15 +308,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformDiffusionTensor3
{
OutputDiffusionTensor3DType outputTensor(inputTensor);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformDiffusionTensor3D(outputTensor);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -379,15 +325,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformDiffusionTensor3
{
OutputVectorPixelType outputTensor(inputTensor);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformDiffusionTensor3D(outputTensor);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -402,16 +344,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformSymmetricSecondR
OutputSymmetricSecondRankTensorType outputTensor(inputTensor);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformSymmetricSecondRankTensor(outputTensor, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -426,16 +364,12 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformSymmetricSecondR
OutputVectorPixelType outputTensor(inputTensor);
OutputPointType outputPoint(inputPoint);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformSymmetricSecondRankTensor(outputTensor, outputPoint);
outputPoint = (*it)->TransformPoint(outputPoint);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -448,15 +382,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformSymmetricSecondR
{
OutputSymmetricSecondRankTensorType outputTensor(inputTensor);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformSymmetricSecondRankTensor(outputTensor);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand All @@ -469,15 +399,11 @@ CompositeTransform<TParametersValueType, NDimensions>::TransformSymmetricSecondR
{
OutputVectorPixelType outputTensor(inputTensor);

typename TransformQueueType::const_iterator it;
/* Apply in reverse queue order. */
it = this->m_TransformQueue.end();

do
for (auto it = this->m_TransformQueue.rbegin(); it != this->m_TransformQueue.rend(); ++it)
{
it--;
outputTensor = (*it)->TransformSymmetricSecondRankTensor(outputTensor);
} while (it != this->m_TransformQueue.begin());
}

return outputTensor;
}
Expand Down Expand Up @@ -702,17 +628,13 @@ CompositeTransform<TParametersValueType, NDimensions>::GetParameters() const

NumberOfParametersType offset = NumericTraits<NumberOfParametersType>::ZeroValue();

auto it = transforms.end();

do
for (auto it = transforms.rbegin(); it != transforms.rend(); ++it)
{
it--;
const ParametersType & subParameters = (*it)->GetParameters();
/* use vnl_vector data_block() to get data ptr */
std::copy_n(subParameters.data_block(), subParameters.Size(), &(this->m_Parameters.data_block())[offset]);
offset += subParameters.Size();

} while (it != transforms.begin());
}
}

return this->m_Parameters;
Expand Down
Loading

0 comments on commit 6eb2bb0

Please sign in to comment.