Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gems and gemsbindings itk5 migration #7

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ set(SOURCES_DYN

# gems libary
add_library(kvlGEMSCommon ${SOURCES})
target_link_libraries(kvlGEMSCommon ${ITK_LIBRARIES} ${ZLIB_LIBRARIES})
target_link_libraries(kvlGEMSCommon ${ZLIB_LIBRARIES} ${ITK_LIBRARIES})

# gems library with dynamic meshes. Needed for `kvlBuildAtlasMesh` but causes
# samseg to run slower, so only link against `kvlGEMSCommon_dynmesh` when nessesary.
add_library(kvlGEMSCommon_dynmesh ${SOURCES_DYN})
target_compile_definitions(kvlGEMSCommon_dynmesh PRIVATE -DUSE_DYNAMIC_MESH)
target_link_libraries(kvlGEMSCommon_dynmesh ${ITK_LIBRARIES} ${ZLIB_LIBRARIES})
target_link_libraries(kvlGEMSCommon_dynmesh ${ZLIB_LIBRARIES} ${ITK_LIBRARIES})

## !!!BAD!!! both `kvlGEMSCommon_dynmesh` `kvlGEMSCommon` will have the same md5sum
## Useful for testing though
Expand Down
31 changes: 24 additions & 7 deletions gems/Executables/kvlAtlasMeshBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ ::TryToCollapseFast( const AtlasMeshCollection* miniCollection,
AtlasMeshCollection::Pointer child;
if ( !miniCollection->GetCollapsed( edgeId, child, disappearingCells, unifiedVertexId ) )
{
return 0;
return nullptr;
}

const AtlasMesh::PointIdentifier unifiedPointId =
Expand Down Expand Up @@ -405,7 +405,7 @@ ::TryToCollapseFast( const AtlasMeshCollection* miniCollection,
}
else
{
return 0;
return nullptr;
}

} // End test if point can move
Expand All @@ -418,7 +418,7 @@ ::TryToCollapseFast( const AtlasMeshCollection* miniCollection,
if ( !costFunction->GetValue( optimalPosition, miniDataCost, miniAlphasCost, miniPositionCost ) )
{
//std::cout << "not possible" << std::endl;
return 0;
return nullptr;
}
//std::cout << " miniDataCost : " << miniDataCost << std::endl;
//std::cout << " miniAlphasCost : " << miniAlphasCost << std::endl;
Expand All @@ -429,7 +429,7 @@ ::TryToCollapseFast( const AtlasMeshCollection* miniCollection,
if ( std::isnan( miniDataCost + miniAlphasCost + miniPositionCost ) ||
std::isinf( miniDataCost + miniAlphasCost + miniPositionCost ) )
{
return 0;
return nullptr;
}
else
{
Expand Down Expand Up @@ -496,11 +496,11 @@ ::TryToRetainFast( const AtlasMeshCollection* miniCollectionConst,
// TODO: should be iterated!
if ( !this->OptimizeReferencePositionFast( miniCollection, vertex0Id, false ) )
{
return 0;
return nullptr;
}
if ( !this->OptimizeReferencePositionFast( miniCollection, vertex1Id, false ) )
{
return 0;
return nullptr;
}


Expand All @@ -513,7 +513,7 @@ ::TryToRetainFast( const AtlasMeshCollection* miniCollectionConst,
if ( ( std::isnan( miniDataCost + miniAlphasCost + miniPositionCost ) ) ||
( std::isinf( miniDataCost + miniAlphasCost + miniPositionCost ) ) )
{
return 0;
return nullptr;
}
else
{
Expand Down Expand Up @@ -1304,16 +1304,29 @@ ::GetRandomizedEdgesAsSet() const
//
//
//
#if ITK_VERSION_MAJOR >= 5
itk::ITK_THREAD_RETURN_TYPE
AtlasMeshBuilder
::LoadBalancedThreaderCallback( void *arg )
#else
ITK_THREAD_RETURN_TYPE
AtlasMeshBuilder
::LoadBalancedThreaderCallback( void *arg )
#endif
{

// Retrieve the input arguments
#if ITK_VERSION_MAJOR >= 5
const int threadId = ((itk::MultiThreaderBase::WorkUnitInfo *)(arg))->WorkUnitID;
//const int threadCount = ((itk::MultiThreaderBase::WorkUnitInfo *)(arg))->NumberOfWorkUnits;

LoadBalancedThreadStruct* str = (LoadBalancedThreadStruct *)(((itk::MultiThreaderBase::WorkUnitInfo *)(arg))->UserData);
#else
const int threadId = ((itk::MultiThreader::ThreadInfoStruct *)(arg))->ThreadID;
//const int threadCount = ((itk::MultiThreader::ThreadInfoStruct *)(arg))->NumberOfThreads;

LoadBalancedThreadStruct* str = (LoadBalancedThreadStruct *)(((itk::MultiThreader::ThreadInfoStruct *)(arg))->UserData);
#endif

const int numberOfEdgesToAnalyze = str->m_Edges.size();
int numberOfEdgesAnalyzed = 0;
Expand Down Expand Up @@ -1358,7 +1371,11 @@ ::LoadBalancedThreaderCallback( void *arg )
}
}

#if ITK_VERSION_MAJOR >= 5
return itk::ITK_THREAD_RETURN_DEFAULT_VALUE;
#else
return ITK_THREAD_RETURN_VALUE;
#endif
}


Expand Down
38 changes: 37 additions & 1 deletion gems/Executables/kvlAtlasMeshBuilder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef __kvlAtlasMeshBuilder_h
#define __kvlAtlasMeshBuilder_h

#if ITK_VERSION_MAJOR >= 5
#include <mutex>
#endif

#include "kvlMultiResolutionAtlasMesher.h"
#include "vnl/vnl_sample.h"
#include "itkTimeProbe.h"
Expand All @@ -11,17 +15,29 @@ namespace kvl
{


#if ITK_VERSION_MAJOR >= 5
class AtlasMeshBuilderMutexLock: public std::mutex
#else
class AtlasMeshBuilderMutexLock: public itk::SimpleFastMutexLock
#endif
{
public:
/** Standard class typedefs. */
typedef AtlasMeshBuilderMutexLock Self;
#if ITK_VERSION_MAJOR >= 5
typedef std::mutex Superclass;
#else
typedef itk::SimpleFastMutexLock Superclass;
#endif

/** Lock access. */
void DescriptiveLock( const std::string& description )
{
#if ITK_VERSION_MAJOR >= 5
Superclass::lock();
#else
Superclass::Lock();
#endif
m_TimeProbe.Start();
m_Description = description;
}
Expand All @@ -31,7 +47,11 @@ class AtlasMeshBuilderMutexLock: public itk::SimpleFastMutexLock
{
m_TimeProbe.Stop();
std::cout << m_Description << ": unlocking mutex after " << m_TimeProbe.GetMean() << " seconds" << std::endl;
#if ITK_VERSION_MAJOR >= 5
Superclass::unlock();
#else
Superclass::Unlock();
#endif
}

protected:
Expand All @@ -58,7 +78,11 @@ class AtlasMeshBuilderHelper
AtlasMeshBuilderHelper( AtlasMeshBuilderMutexLock& mutex, std::map< AtlasMesh::PointIdentifier, int >& pointOccupancies )
: m_Mutex( mutex ), m_MutexIsLocked( true ), m_PointOccupancies( pointOccupancies )
{
m_Mutex.Lock();
#if ITK_VERSION_MAJOR >= 5
m_Mutex.lock();
#else
m_Mutex.Lock();
#endif
}


Expand All @@ -74,7 +98,11 @@ class AtlasMeshBuilderHelper
if ( !m_MutexIsLocked )
{
m_MutexIsLocked = true;
#if ITK_VERSION_MAJOR >= 5
m_Mutex.lock();
#else
m_Mutex.Lock();
#endif
}

}
Expand All @@ -84,7 +112,11 @@ class AtlasMeshBuilderHelper
if ( m_MutexIsLocked )
{
m_MutexIsLocked = false;
#if ITK_VERSION_MAJOR >= 5
m_Mutex.unlock();
#else
m_Mutex.Unlock();
#endif
}
}

Expand Down Expand Up @@ -319,7 +351,11 @@ protected :
/** Static function used as a "callback" by the MultiThreader. The threading
* library will call this routine for each thread, which will delegate the
* control to ThreadedGenerateData(). */
#if ITK_VERSION_MAJOR >= 5
static itk::ITK_THREAD_RETURN_TYPE LoadBalancedThreaderCallback( void *arg );
#else
static ITK_THREAD_RETURN_TYPE LoadBalancedThreaderCallback( void *arg );
#endif

/** Internal structure used for passing image data into the threading library */
struct LoadBalancedThreadStruct
Expand Down
2 changes: 1 addition & 1 deletion gems/Executables/kvlBuildAtlasMesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int main( int argc, char** argv )


// If explicitStartCollection exists in the current directory, use it
kvl::AtlasMeshCollection::Pointer explicitStartCollection = 0;
kvl::AtlasMeshCollection::Pointer explicitStartCollection = nullptr;
const std::string explicitStartCollectionFileName = "explicitStartCollection.gz";
if ( itksys::SystemTools::FileExists( explicitStartCollectionFileName.c_str(), true ) )
{
Expand Down
4 changes: 4 additions & 0 deletions gems/itkMGHImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
// ITK includes
#include "itkImageIOBase.h"
#include "itkIOCommon.h"
#if ITK_VERSION_MAJOR >= 5
#include "itkMacro.h"
#else
#include "itkExceptionObject.h"
#endif
#include "itkByteSwapper.h"
#include "itkMetaDataObject.h"
#include "itkMatrix.h"
Expand Down
16 changes: 8 additions & 8 deletions gems/kvlAtlasMeshCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ ::GetCollapsed( AtlasMesh::CellIdentifier edgeId,
// disappears, and first point, which gets the previously determined new position
//std::cout << "Creating positions" << std::endl;
std::vector< PointsContainerType::Pointer > collapsedPositions;
PointsContainerType::Pointer collapsedReferencePosition = 0;
PointsContainerType::Pointer collapsedReferencePosition = nullptr;
for ( unsigned int meshNumber = 0; meshNumber < this->GetNumberOfMeshes()+1; meshNumber++ )
{
PointsContainerType::Pointer thisPosition;
Expand Down Expand Up @@ -1857,7 +1857,7 @@ ::GetRegionGrown( AtlasMesh::CellIdentifier seedId, unsigned int radius, bool ma
if ( !( m_Cells->IndexExists( seedId ) ) )
{
// Cell simply doesn't exist.
return 0;
return nullptr;
}

// Get the cell
Expand Down Expand Up @@ -2353,7 +2353,7 @@ ::GetUpsampled() const

// Loop over all meshes, including reference
std::vector< PointsContainerType::Pointer > upsampledPositions;
PointsContainerType::Pointer upsampledReferencePosition = 0;
PointsContainerType::Pointer upsampledReferencePosition = nullptr;
CellsContainerType::Pointer upsampledCells;
for ( unsigned int meshNumber=0; meshNumber < this->GetNumberOfMeshes()+1; meshNumber++ )
{
Expand Down Expand Up @@ -2985,7 +2985,7 @@ ::GetUpsampled() const
if ( upsampledPositions[ meshNumber ]->Size() != upsampledReferencePosition->Size() )
{
std::cerr << "Upsampling failed because of numerical inaccuracies!" << std::endl;
return 0;
return nullptr;
}
}

Expand Down Expand Up @@ -3085,7 +3085,7 @@ ::GetEdgeSplitted( AtlasMesh::CellIdentifier edgeId,

return this->GetEdgeSplitted( edgeId, newVertexId, newPointId, transverseEdge0IdDummy, transverseEdge1IdDummy );
#else
return 0;
return nullptr;
#endif

}
Expand All @@ -3112,7 +3112,7 @@ ::GetEdgeSwapped( AtlasMesh::CellIdentifier edgeId ) const
AtlasMesh::CellIdentifier newEdgeIdDummy;
return this->GetEdgeSwapped( edgeId, newVertexId, newPointId, newEdgeIdDummy );
#else
return 0;
return nullptr;
#endif
}

Expand Down Expand Up @@ -3232,7 +3232,7 @@ ::GetEdgeSwapped( AtlasMesh::CellIdentifier edgeId,
return collapsed;

#else
return 0;
return nullptr;

#endif
}
Expand Down Expand Up @@ -3591,7 +3591,7 @@ ::GetEdgeSplitted( AtlasMesh::CellIdentifier edgeId,
return splitted;

#else
return 0;
return nullptr;
#endif

}
Expand Down
2 changes: 1 addition & 1 deletion gems/kvlAtlasMeshDeformationConjugateGradientOptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ::FindAndOptimizeNewSearchDirection()
//
// Part I: Decide on a new search direction
//
AtlasPositionGradientContainerType::Pointer searchDirection = 0;
AtlasPositionGradientContainerType::Pointer searchDirection = nullptr;
bool startingOrRestarting = false;
if ( this->GetIterationNumber() == 0 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ ::FindAndOptimizeNewSearchDirection()
// Try to add the scaled gradient to the current position to obtain the trial position
const double alpha = -( m_StepSize / maximumGradientMagnitude );
double maximalDeformation = 0.0;
AtlasMesh::PointsContainer::Pointer trialPosition = 0;
AtlasMesh::PointsContainer::Pointer trialPosition = nullptr;
this->AddDeformation( m_Position, alpha, m_Gradient, trialPosition, maximalDeformation );
if ( m_Verbose )
{
std::cout << "Using trialPosition with maximalDeformation: " << maximalDeformation << std::endl;
}

// Try out this new position
AtlasPositionGradientContainerType::Pointer trialGradient = 0;
AtlasPositionGradientContainerType::Pointer trialGradient = nullptr;
double trialCost = 0.0;
this->GetCostAndGradient( trialPosition, trialCost, trialGradient );
if ( m_Verbose )
Expand Down
12 changes: 6 additions & 6 deletions gems/kvlAtlasMeshDeformationOptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,24 @@ ::DoLineSearch( const AtlasMesh::PointsContainer* startPosition,
const int maximumOfBracketingIterations = 10;
double lowAlpha = 0.0;
double lowCost = 0.0;
AtlasPositionGradientContainerType::ConstPointer lowGradient = 0;
AtlasPositionGradientContainerType::ConstPointer lowGradient = nullptr;
double lowDirectionalDerivative = 0.0;
double highAlpha = 0.0;
double highCost = 0.0;
AtlasPositionGradientContainerType::ConstPointer highGradient = 0;
AtlasPositionGradientContainerType::ConstPointer highGradient = nullptr;
double highDirectionalDerivative = 0.0;

for ( int bracketingIterationNumber = 0;
bracketingIterationNumber < maximumOfBracketingIterations;
bracketingIterationNumber++ )
{
// Evaluate current alpha: [ cost gradient ] = tryFunction( x + alpha * p );
AtlasMesh::PointsContainer::Pointer position = 0;
AtlasMesh::PointsContainer::Pointer position = nullptr;
double maximalDeformation = 0.0;
this->AddDeformation( startPosition, alpha, searchDirection,
position, maximalDeformation );
double cost;
AtlasPositionGradientContainerType::Pointer gradient = 0;
AtlasPositionGradientContainerType::Pointer gradient = nullptr;
this->GetCostAndGradient( position, cost, gradient );
const double directionalDerivative = this->ComputeInnerProduct( gradient, searchDirection ); // gradient' * p

Expand Down Expand Up @@ -721,12 +721,12 @@ ::DoLineSearch( const AtlasMesh::PointsContainer* startPosition,
#endif

// Evaluate cost function: [ cost gradient ] = tryFunction( x + alpha * p );
AtlasMesh::PointsContainer::Pointer position = 0;
AtlasMesh::PointsContainer::Pointer position = nullptr;
double maximalDeformation = 0.0;
this->AddDeformation( startPosition, alpha, searchDirection,
position, maximalDeformation );
double cost;
AtlasPositionGradientContainerType::Pointer gradient = 0;
AtlasPositionGradientContainerType::Pointer gradient = nullptr;
this->GetCostAndGradient( position, cost, gradient );
const double directionalDerivative = this->ComputeInnerProduct( gradient, searchDirection ); // gradient' * p

Expand Down
2 changes: 1 addition & 1 deletion gems/kvlAtlasMeshPositionCostAndGradientCalculator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ AtlasMeshPositionCostAndGradientCalculator
::SetMeshToImageTransform( const TransformType* meshToImageTransform )
{

TransformType::Pointer inScopeHolder = 0;
TransformType::Pointer inScopeHolder = nullptr;
if ( !meshToImageTransform )
{
//meshToImageTransform = TransformType::New();
Expand Down
Loading
Loading