From 3a2e2acdcf35146a7016a9be56ff366208e0d4be Mon Sep 17 00:00:00 2001 From: delmon Date: Tue, 11 Jan 2011 10:37:42 +0000 Subject: [PATCH] Add a boolean to Reset the jacobian memory just when it is needed. Add SetJacobianImageData and friendship with MultipleBSplineDeformableTransform to facilitate and optimise wrapping. --- .../clitkBSplineDeformableTransform.h | 14 ++- .../clitkBSplineDeformableTransform.txx | 108 +++++++++--------- 2 files changed, 68 insertions(+), 54 deletions(-) diff --git a/registration/clitkBSplineDeformableTransform.h b/registration/clitkBSplineDeformableTransform.h index 2aeaac6..4ea8b58 100644 --- a/registration/clitkBSplineDeformableTransform.h +++ b/registration/clitkBSplineDeformableTransform.h @@ -27,6 +27,9 @@ namespace clitk { + // Forward declaration needed for friendship + template + class ITK_EXPORT MultipleBSplineDeformableTransform; template < class TCoordRep = double, // Data type for scalars, coordinate representation,vectors @@ -186,7 +189,7 @@ namespace clitk void SetBulkTransform(BulkTransformPointer b){m_BulkTransform=b;} BulkTransformPointer GetBulkTransform(void) {return m_BulkTransform;} - //Set mask, inside transform applies, outside zero, real pointer + // Set mask, inside transform applies, outside zero, real pointer void SetMask(MaskPointer m){m_Mask=m;} MaskPointer GetMask(void){return m_Mask;} // itkSetConstObjectMacro( Mask, MaskType ); @@ -338,6 +341,7 @@ namespace clitk mutable IteratorType m_Iterator[OutputDimension]; mutable JacobianPixelType m_ZeroVector; mutable ContinuousIndexType m_Index; + mutable bool m_NeedResetJacobian; /** Keep a pointer to the input parameters. */ const ParametersType * m_InputParametersPointer; @@ -351,6 +355,14 @@ namespace clitk /** Check if a continuous index is inside the valid region. */ bool InsideValidRegion( const ContinuousIndexType& index ) const; + // VD Use external data container for JacobianImage + unsigned SetJacobianImageData(JacobianPixelType * jacobianDataPointer, unsigned dim); + + // VD Reset Jacobian + void ResetJacobian() const; + + // VD Add MultipleBSplineDeformableTransform as friend to facilitate wrapping + friend class MultipleBSplineDeformableTransform; }; //class BSplineDeformableTransform diff --git a/registration/clitkBSplineDeformableTransform.txx b/registration/clitkBSplineDeformableTransform.txx index 4290191..23851a2 100644 --- a/registration/clitkBSplineDeformableTransform.txx +++ b/registration/clitkBSplineDeformableTransform.txx @@ -86,14 +86,7 @@ namespace clitk for (i=0; i ::Zero; - } @@ -204,28 +196,20 @@ namespace clitk BSplineDeformableTransform ::SetSplineOrders(const SizeType & splineOrders) { - if(m_SplineOrders!=splineOrders) + if (m_SplineOrders!=splineOrders) { m_SplineOrders=splineOrders; //update the interpolation function m_VectorInterpolator->SetSplineOrders(m_SplineOrders); - //update the varaibles for computing interpolation + //update the variables for computing interpolation for (unsigned int i=0; i Modified(); } } @@ -271,7 +255,6 @@ namespace clitk BSplineDeformableTransform ::GetNumberOfParameters(void) const { - // The number of parameters equal OutputDimension * number of // of pixels in the grid region. return ( static_cast( OutputDimension ) * @@ -307,7 +290,7 @@ namespace clitk m_WrappedImage->SetRegions( m_GridRegion ); for (unsigned int j=0; j SetRegions( m_GridRegion ); - + // Set the valid region // If the grid spans the interval [start, last]. // The valid interval for evaluation is [start+offset, last-offset] @@ -448,7 +431,6 @@ namespace clitk } } - // Set the parameters template void @@ -600,6 +582,7 @@ namespace clitk JacobianPixelType * jacobianDataPointer = reinterpret_cast(this->m_Jacobian.data_block()); memset(jacobianDataPointer, 0, OutputDimension*numberOfPixels*sizeof(JacobianPixelType)); m_LastJacobianIndex = m_ValidRegion.GetIndex(); + m_NeedResetJacobian = false; for (unsigned int j=0; jm_Jacobian; @@ -1037,7 +998,48 @@ namespace clitk } } + template + unsigned + BSplineDeformableTransform + ::SetJacobianImageData(JacobianPixelType * jacobianDataPointer, unsigned dim) + { + unsigned int numberOfPixels = m_GridRegion.GetNumberOfPixels(); + m_JacobianImage[dim]->GetPixelContainer()->SetImportPointer(jacobianDataPointer, numberOfPixels); + return numberOfPixels; + } + template + void + BSplineDeformableTransform + ::ResetJacobian() const + { + //======================================================== + // Zero all components of jacobian + //======================================================== + // JV not thread safe (m_LastJacobianIndex), instantiate N transforms + // NOTE: for efficiency, we only need to zero out the coefficients + // that got fill last time this method was called. + + unsigned int j = 0; + + //Define the region for each jacobian image + m_SupportRegion.SetIndex(m_LastJacobianIndex); + + //Initialize the iterators + for (j = 0; j < OutputDimension; j++) + m_Iterator[j] = IteratorType(m_JacobianImage[j], m_SupportRegion); + + //Set the previously-set to zero + while (!(m_Iterator[0]).IsAtEnd()) + { + for (j = 0; j < OutputDimension; j++) + { + m_Iterator[j].Set(m_ZeroVector); + ++(m_Iterator[j]); + } + } + m_NeedResetJacobian = false; + } } // namespace #endif -- 2.45.1