This class allows to cache the stats for sections.
Using this class instead of Section or NeuronMorphologySectionStats when constructing the hierarchy allows to call the method stats from base NeuronMorphologySection class and get the corresponding volume, surface and length. If the cached value is dirty then the actual computation process is done. In case is clean the cached value is returned directly.
#include <nsol/nsol.h>
#include <stack>
int main ( int argc, char ** argv )
{
std::cout << std::endl;
if ( argc < 2 )
{
std::cerr << "Error. Usage: " << argv[0]
<< " swc_input_file" << std::endl;
return -1;
}
std::cout << "Reading neuron without stats" << std::endl;
std::cout << "Reading neuron with stats" << std::endl;
std::cout << "Reading neuron with cached stats" << std::endl;
if ( ! neuron || ! neuronWithStats || ! neuronWithCachedStats )
{
std::cerr << "Could not read neurons" << std::endl;
return -1;
}
neuron->morphology( )->neurites( )[0]->firstSection( );
neuronWithStats->morphology( )->neurites()[0]->firstSection( );
neuronWithCachedStats->morphology( )->neurites()[0]->firstSection( );
if ( ! section || ! sectionWithStats || ! sectionWithCachedStats )
{
std::cerr << "Could not get sections of first neurite" << std::endl;
return -1;
}
std::cout << std::endl;
NSOL_CHECK_THROW ( section->
stats( ) ==
nullptr,
"stats not null" );
NSOL_CHECK_THROW ( sectionWithStats->
stats( ) !=
nullptr,
"stats null" );
( sectionWithCachedStats->
stats( ));
NSOL_CHECK_THROW( sectionCached, "non cached section" );
#define PRINT_SURFACE_DIRTY_STATE( section ) \
(( section->dirty(nsol::NeuronMorphologySectionCachedStats::SURFACE) ) ? \
"Dirty" : "Clean" )
std::cout << std::endl;
std::cout << "Surface of the first section of the first neurite "
<< std::endl;
std::cout << "\tNon cached section: "
<< sectionWithStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
sectionCached->setDirty( nsol::NeuronMorphologySectionCachedStats::SURFACE );
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
sectionCached->setAndPropagateDirty( );
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << "\tCached section ("
<< PRINT_SURFACE_DIRTY_STATE( sectionCached ) << "): ";
std::cout << sectionWithCachedStats->
stats( )->getStat(
SURFACE ) << std::endl;
std::cout << std::endl;
int j = 0;
for ( const auto& neurite : neuronWithCachedStats->morphology( )->neurites( ))
{
std::cout << "Neurite " << j << std::endl;
std::stack< nsol::SectionPtr > sSP;
sSP.push( neuriteSection );
int k = 0;
while ( !sSP.empty( ))
{
sSP.top( ));
sSP.pop( );
std::cout << " Section " << k << std::endl;
std::cout <<
" Surface " << neuriteSection->
stats( )->getStat(
nsol::NeuronMorphologySectionStats::SURFACE ) << std::endl;
std::cout <<
" Volume " << neuriteSection->
stats( )->getStat(
nsol::NeuronMorphologySectionStats::VOLUME ) << std::endl;
std::cout <<
" Length " << neuriteSection->
stats( )->getStat(
nsol::NeuronMorphologySectionStats::LENGTH ) << std::endl;
for (
const auto& sec : section->
children( ))
sSP.push( sec );
++k;
}
++j;
}
return 0;
}