diff --git a/brain/CMakeLists.txt b/brain/CMakeLists.txt index 57e3417..527c4a5 100644 --- a/brain/CMakeLists.txt +++ b/brain/CMakeLists.txt @@ -6,7 +6,6 @@ set(BRAIN_PUBLIC_HEADERS circuit.h - enums.h neuron/morphology.h neuron/section.h neuron/soma.h diff --git a/brain/circuit.cpp b/brain/circuit.cpp index ad704cc..08555ca 100644 --- a/brain/circuit.cpp +++ b/brain/circuit.cpp @@ -100,7 +100,7 @@ neuron::Morphologies Circuit::loadMorphologies( const GIDSet& gids, { std::string hash( fs::canonical( uris[i].getPath( )).generic_string( )); - if( coords == COORDINATES_GLOBAL ) + if( coords == Coordinates::global ) { // store circuit + GID for transformed morphology hash += fs::canonical( @@ -122,7 +122,7 @@ neuron::Morphologies Circuit::loadMorphologies( const GIDSet& gids, result.reserve( uris.size( )); const Matrix4fs transforms = - coords == COORDINATES_GLOBAL ? getTransforms( gids ) : Matrix4fs(); + coords == Coordinates::global ? getTransforms( gids ) : Matrix4fs(); for( size_t i = 0; i < uris.size(); ++i ) { const URI& uri = uris[i]; @@ -133,7 +133,7 @@ neuron::Morphologies Circuit::loadMorphologies( const GIDSet& gids, { neuron::MorphologyPtr morphology; const brion::Morphology raw( uri.getPath( )); - if( coords == COORDINATES_GLOBAL ) + if( coords == Coordinates::global ) morphology.reset( new neuron::Morphology( raw, transforms[i] )); else morphology.reset( new neuron::Morphology( raw )); diff --git a/brain/circuit.h b/brain/circuit.h index 33ee5cb..9bfc60e 100644 --- a/brain/circuit.h +++ b/brain/circuit.h @@ -40,10 +40,10 @@ class Circuit { public: /** Coordinate system to use for circuit morphologies */ - enum Coordinates + enum class Coordinates { - COORDINATES_GLOBAL, - COORDINATES_LOCAL + global, + local }; /** @@ -134,8 +134,9 @@ class Circuit * @param prefetch which synapse data to load on SynapsesStream.read() * @return synapse data stream */ - BRAIN_API SynapsesStream getAfferentSynapses( const GIDSet& gids, - SynapsePrefetch prefetch = SYNAPSEPREFETCH_ALL ) const; + BRAIN_API SynapsesStream getAfferentSynapses( + const GIDSet& gids, + SynapsePrefetch prefetch = SynapsePrefetch::all ) const; /** * Access all efferent synapses of the given GIDs. @@ -144,8 +145,9 @@ class Circuit * @param prefetch which synapse data to load on SynapsesStream.read() * @return synapse data stream */ - BRAIN_API SynapsesStream getEfferentSynapses( const GIDSet& gids, - SynapsePrefetch prefetch = SYNAPSEPREFETCH_ALL ) const; + BRAIN_API SynapsesStream getEfferentSynapses( + const GIDSet& gids, + SynapsePrefetch prefetch = SynapsePrefetch::all ) const; /** * Access all synapses along the projection from the pre- to the postGIDs. @@ -155,9 +157,9 @@ class Circuit * @param prefetch which synapse data to load on SynapsesStream.read() * @return synapse data stream */ - BRAIN_API SynapsesStream getProjectedSynapses( const GIDSet& preGIDs, - const GIDSet& postGIDs, - SynapsePrefetch prefetch = SYNAPSEPREFETCH_ALL ) const; + BRAIN_API SynapsesStream getProjectedSynapses( + const GIDSet& preGIDs, const GIDSet& postGIDs, + SynapsePrefetch prefetch = SynapsePrefetch::all ) const; class Impl; //!< @internal, public for inheritance MVD2/3 impls diff --git a/brain/enums.h b/brain/enums.h deleted file mode 100644 index 92f63fc..0000000 --- a/brain/enums.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2013-2016, EPFL/Blue Brain Project - * Daniel.Nachbaur@epfl.ch - * - * This file is part of Brion - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file brain/enums.h Enumerations used in Brion. */ - -#ifndef BRAIN_ENUMS -#define BRAIN_ENUMS - -#include - -namespace brain -{ -namespace enums -{ - -using namespace brion::enums; - -/** - * Loading of data during SynapsesStream::read(), otherwise load happens - * on-demand. - */ -enum SynapsePrefetch -{ - SYNAPSEPREFETCH_NONE = 0, //!< only loads pre- and post GIDs - SYNAPSEPREFETCH_ATTRIBUTES = 1 << 0, //!< topological information (section, - //! segment, distance) and model - //! attributes - SYNAPSEPREFETCH_POSITIONS = 1 << 1, //!< pre/post surface/center positions - SYNAPSEPREFETCH_ALL = //!< all synapse data - SYNAPSEPREFETCH_ATTRIBUTES | SYNAPSEPREFETCH_POSITIONS -}; - -} -} -#endif diff --git a/brain/neuron/morphology.cpp b/brain/neuron/morphology.cpp index 689179e..ec85df2 100644 --- a/brain/neuron/morphology.cpp +++ b/brain/neuron/morphology.cpp @@ -91,7 +91,7 @@ const Vector2is& Morphology::getSections() const const SectionTypes& Morphology::getSectionTypes() const { - return *_impl->types; + return reinterpret_cast< std::vector& >( *_impl->types ); } const Vector2is& Morphology::getApicals() const @@ -125,7 +125,7 @@ Sections Morphology::getSections( const SectionTypes& types ) const Section Morphology::getSection( const uint32_t& id ) const { - if(( *_impl->types )[id] == SECTION_SOMA ) + if(( *_impl->types )[id] == brion::enums::SECTION_SOMA ) LBTHROW( std::runtime_error( "The soma cannot be accessed as a Section" )); diff --git a/brain/neuron/morphology.h b/brain/neuron/morphology.h index 0d386d0..137be68 100644 --- a/brain/neuron/morphology.h +++ b/brain/neuron/morphology.h @@ -95,7 +95,9 @@ class Morphology : public boost::noncopyable /** @sa brion::Morphology::readSections */ BRAIN_API const Vector2is& getSections() const; - /** @sa brion::Morphology::readSectionTypes */ + /** @sa brion::Morphology::readSectionTypes + This type is not brain::SectionTypes because brion::SectionType + is not convertible to brain::neuron::SectionType. */ BRAIN_API const SectionTypes& getSectionTypes() const; /** @sa brion::Morphology::readApicals */ @@ -106,13 +108,13 @@ class Morphology : public boost::noncopyable /** * Return the sections which have the given section type. - * If type is SECTION_SOMA an empty list is returned. + * If type is SectionType::Soma an empty list is returned. */ BRAIN_API Sections getSections( SectionType type ) const; /** * Return the sections which have any of the given section types. - * No sections are returned for the type SECTION_SOMA. + * No sections are returned for the type SectionType::Soma. */ BRAIN_API Sections getSections( const SectionTypes& types ) const; diff --git a/brain/neuron/morphologyImpl.cpp b/brain/neuron/morphologyImpl.cpp index 8efdc58..fc529df 100644 --- a/brain/neuron/morphologyImpl.cpp +++ b/brain/neuron/morphologyImpl.cpp @@ -36,7 +36,7 @@ namespace neuron namespace { template< typename T > -void _serializeArray( uint8_t*& dst, +void _serializeArray( unsigned char*& dst, const boost::shared_ptr< std::vector< T > >& src ) { const size_t arraySize = src->size(); @@ -48,7 +48,7 @@ void _serializeArray( uint8_t*& dst, template< typename T > void _deserializeArray( boost::shared_ptr< std::vector< T > >& dst, - const uint8_t*& src ) + const unsigned char*& src ) { const size_t arraySize = *reinterpret_cast< const size_t* >( src ); src += sizeof(size_t); @@ -66,16 +66,14 @@ Morphology::Impl::Impl( const void* data, const size_t size ) } Morphology::Impl::Impl( const brion::Morphology& morphology ) - : points( morphology.readPoints( MORPHOLOGY_UNDEFINED )) - , sections( morphology.readSections( MORPHOLOGY_UNDEFINED )) + : points( morphology.readPoints( brion::enums::MORPHOLOGY_UNDEFINED )) + , sections( morphology.readSections( brion::enums::MORPHOLOGY_UNDEFINED )) , types( morphology.readSectionTypes( )) , apicals( morphology.readApicals( )) { _extractChildrenLists(); - const uint32_ts ids = - getSectionIDs( SectionTypes( 1, SECTION_SOMA ), false ); - + const uint32_ts ids = getSectionIDs({ SectionType::soma }, false ); if( ids.size() != 1 ) LBTHROW( std::runtime_error( "Bad input morphology. None or more than one soma found" )); @@ -84,18 +82,17 @@ Morphology::Impl::Impl( const brion::Morphology& morphology ) bool Morphology::Impl::_fromBinary( const void* data, const size_t size ) { - const uint8_t* ptr = reinterpret_cast< const uint8_t* >( data ); + const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data ); _deserializeArray( points, ptr ); _deserializeArray( sections, ptr ); _deserializeArray( types, ptr ); - if( size_t(ptr - reinterpret_cast< const uint8_t* >( data )) < size ) + if( size_t(ptr - reinterpret_cast< const unsigned char* >( data )) < size ) _deserializeArray( apicals, ptr ); _extractChildrenLists(); - const uint32_ts ids = - getSectionIDs( SectionTypes( 1, SECTION_SOMA ), false ); + const uint32_ts ids = getSectionIDs({ SectionType::soma }, false ); if( ids.size() != 1 ) LBTHROW( std::runtime_error( @@ -114,7 +111,7 @@ servus::Serializable::Data Morphology::Impl::_toBinary() const if( !apicals->empty( )) data.size += sizeof(size_t) + sizeof(brion::Vector2i) * apicals->size(); - uint8_t* ptr = new uint8_t[data.size]; + unsigned char* ptr = new unsigned char[data.size]; data.ptr.reset( ptr ); _serializeArray( ptr, points ); @@ -137,17 +134,17 @@ SectionRange Morphology::Impl::getSectionRange( const uint32_t sectionID ) const uint32_ts Morphology::Impl::getSectionIDs( const SectionTypes& requestedTypes, const bool excludeSoma ) const { - std::bitset< SECTION_APICAL_DENDRITE > bits; + std::bitset< size_t( SectionType::apicalDendrite )> bits; BOOST_FOREACH( const SectionType type, requestedTypes ) { - if( type != SECTION_SOMA || !excludeSoma ) + if( type != SectionType::soma || !excludeSoma ) bits[size_t( type )] = true; } uint32_ts result; for( size_t i = 0; i != types->size(); ++i ) { - const SectionType type = ( *types )[i]; + const SectionType type = static_cast< SectionType >(( *types )[i] ); if( bits[size_t( type )] ) result.push_back( i ); } @@ -161,7 +158,7 @@ float Morphology::Impl::getSectionLength( const uint32_t sectionID ) const float& length = _sectionLengths[sectionID]; - if( length == 0 && ( *types )[sectionID] != SECTION_SOMA ) + if( length == 0 && ( *types )[sectionID] != brion::enums::SECTION_SOMA ) length = _computeSectionLength( sectionID ); return length; } @@ -177,12 +174,12 @@ Vector4fs Morphology::Impl::getSectionSamples( const uint32_t sectionID ) const } Vector4fs Morphology::Impl::getSectionSamples( const uint32_t sectionID, - const floats& samplePoints ) const + const floats& samplePoints ) const { const SectionRange range = getSectionRange( sectionID ); // If the section is the soma return directly the soma position. - if(( *types )[sectionID] == SECTION_SOMA ) + if(( *types )[sectionID] == brion::enums::SECTION_SOMA ) // This code shouldn't be reached. LBTHROW( std::runtime_error( "Invalid method called on soma section" )); @@ -206,10 +203,20 @@ Vector4fs Morphology::Impl::getSectionSamples( const uint32_t sectionID, index < accumLengths.size() - 1; ++index ) ; + // If the first point of the section is repeated and we are interpolating + // at 0 length - accumLengths[0] and accumLengths[1] - accumLengths[0] + // will be both 0. To avoid the 0/0 operation we check for + // length == accumLengths[index]. + const size_t start = range.first + index; + if( length == accumLengths[index] ) + { + result.push_back(( *points )[start] ); + continue; + } + // Interpolating the cross section at point. const float alpha = ( length - accumLengths[index] ) / - ( accumLengths[index + 1] - accumLengths[index] ); - const size_t start = range.first + index; + ( accumLengths[index + 1] - accumLengths[index] ); const Vector4f sample = ( *points )[start + 1] * alpha + ( *points )[start] * (1 - alpha ); result.push_back( sample ); @@ -230,7 +237,7 @@ float Morphology::Impl::getDistanceToSoma( const uint32_t sectionID ) const // been computed yet. Soma and first order sections are cheap // to detect and compute. const int32_t parent = ( *sections )[sectionID][1]; - if( parent == -1 || ( *types )[parent] == SECTION_SOMA ) + if( parent == -1 || ( *types )[parent] == brion::enums::SECTION_SOMA ) return 0; // For the other cases it doesn't matter to have concurrent updates // because they will yield the same result (and it's probably diff --git a/brain/neuron/section.cpp b/brain/neuron/section.cpp index f3b866f..11ece0a 100644 --- a/brain/neuron/section.cpp +++ b/brain/neuron/section.cpp @@ -82,7 +82,7 @@ uint32_t Section::getID() const SectionType Section::getType() const { - return ( *_morphology->types )[_id]; + return static_cast< SectionType >(( *_morphology->types )[_id] ); } float Section::getLength() const diff --git a/brain/neuron/section.h b/brain/neuron/section.h index e3b76ea..53e1b53 100644 --- a/brain/neuron/section.h +++ b/brain/neuron/section.h @@ -67,7 +67,7 @@ class Section /** Return the ID of this section. */ BRAIN_API uint32_t getID() const; - /** Return the morphological type of this section (dedrite, axon, ...). */ + /** Return the morphological type of this section (dendrite, axon, ...). */ BRAIN_API SectionType getType() const; /** diff --git a/brain/neuron/types.h b/brain/neuron/types.h index 537f436..6f3355f 100644 --- a/brain/neuron/types.h +++ b/brain/neuron/types.h @@ -22,6 +22,7 @@ #include #include +#include namespace brain { @@ -32,10 +33,20 @@ class Morphology; class Section; class Soma; +enum class SectionType +{ + soma = brion::enums::SECTION_SOMA, + axon = brion::enums::SECTION_AXON, + dendrite = brion::enums::SECTION_DENDRITE, + apicalDendrite = brion::enums::SECTION_APICAL_DENDRITE, + undefined = brion::enums::SECTION_UNDEFINED +}; + typedef boost::shared_ptr< Morphology > MorphologyPtr; typedef std::vector< MorphologyPtr > Morphologies; typedef std::vector< Section > Sections; +typedef std::vector< SectionType > SectionTypes; } } diff --git a/brain/synapse.cpp b/brain/synapse.cpp index 02897a4..386c7ff 100644 --- a/brain/synapse.cpp +++ b/brain/synapse.cpp @@ -39,110 +39,110 @@ Synapse::~Synapse() SynapseGID Synapse::getGID() const { return std::make_pair( getPostsynapticGID(), - _synapses.index()[_index] ); + _synapses.indices()[_index] ); } uint32_t Synapse::getPresynapticGID() const { - return _synapses.preGID()[_index]; + return _synapses.preGIDs()[_index]; } uint32_t Synapse::getPresynapticSectionID() const { - return _synapses.preSectionID()[_index]; + return _synapses.preSectionIDs()[_index]; } uint32_t Synapse::getPresynapticSegmentID() const { - return _synapses.preSegmentID()[_index]; + return _synapses.preSegmentIDs()[_index]; } float Synapse::getPresynapticDistance() const { - return _synapses.preDistance()[_index]; + return _synapses.preDistances()[_index]; } Vector3f Synapse::getPresynapticSurfacePosition() const { - return Vector3f( _synapses.preSurfacePositionX()[_index], - _synapses.preSurfacePositionY()[_index], - _synapses.preSurfacePositionZ()[_index] ); + return Vector3f( _synapses.preSurfaceXPositions()[_index], + _synapses.preSurfaceYPositions()[_index], + _synapses.preSurfaceZPositions()[_index] ); } Vector3f Synapse::getPresynapticCenterPosition() const { - return Vector3f( _synapses.preCenterPositionX()[_index], - _synapses.preCenterPositionY()[_index], - _synapses.preCenterPositionZ()[_index] ); + return Vector3f( _synapses.preCenterXPositions()[_index], + _synapses.preCenterYPositions()[_index], + _synapses.preCenterZPositions()[_index] ); } uint32_t Synapse::getPostsynapticGID() const { - return _synapses.postGID()[_index]; + return _synapses.postGIDs()[_index]; } uint32_t Synapse::getPostsynapticSectionID() const { - return _synapses.postSectionID()[_index]; + return _synapses.postSectionIDs()[_index]; } uint32_t Synapse::getPostsynapticSegmentID() const { - return _synapses.postSegmentID()[_index]; + return _synapses.postSegmentIDs()[_index]; } float Synapse::getPostsynapticDistance() const { - return _synapses.postDistance()[_index]; + return _synapses.postDistances()[_index]; } Vector3f Synapse::getPostsynapticSurfacePosition() const { - return Vector3f( _synapses.postSurfacePositionX()[_index], - _synapses.postSurfacePositionY()[_index], - _synapses.postSurfacePositionZ()[_index] ); + return Vector3f( _synapses.postSurfaceXPositions()[_index], + _synapses.postSurfaceYPositions()[_index], + _synapses.postSurfaceZPositions()[_index] ); } Vector3f Synapse::getPostsynapticCenterPosition() const { - return Vector3f( _synapses.postCenterPositionX()[_index], - _synapses.postCenterPositionY()[_index], - _synapses.postCenterPositionZ()[_index] ); + return Vector3f( _synapses.postCenterXPositions()[_index], + _synapses.postCenterYPositions()[_index], + _synapses.postCenterZPositions()[_index] ); } float Synapse::getDelay() const { - return _synapses.delay()[_index]; + return _synapses.delays()[_index]; } float Synapse::getConductance() const { - return _synapses.conductance()[_index]; + return _synapses.conductances()[_index]; } float Synapse::getUtilization() const { - return _synapses.utilization()[_index]; + return _synapses.utilizations()[_index]; } float Synapse::getDepression() const { - return _synapses.depression()[_index]; + return _synapses.depressions()[_index]; } float Synapse::getFacilitation() const { - return _synapses.facilitation()[_index]; + return _synapses.facilitations()[_index]; } float Synapse::getDecay() const { - return _synapses.decay()[_index]; + return _synapses.decays()[_index]; } int Synapse::getEfficacy() const { - return _synapses.efficacy()[_index]; + return _synapses.efficacys()[_index]; } } diff --git a/brain/synapses.cpp b/brain/synapses.cpp index 3b0bd87..db3d30c 100644 --- a/brain/synapses.cpp +++ b/brain/synapses.cpp @@ -63,20 +63,20 @@ struct Synapses::Impl Impl( const Circuit& circuit, const GIDSet& gids, const GIDSet& filterGIDs, const bool afferent, const SynapsePrefetch prefetch ) : _circuit( circuit ) - , _gids( prefetch != SYNAPSEPREFETCH_ALL ? gids : GIDSet( )) - , _filterGIDs( prefetch != SYNAPSEPREFETCH_ALL ? filterGIDs : GIDSet( )) + , _gids( prefetch != SynapsePrefetch::all ? gids : GIDSet( )) + , _filterGIDs( prefetch != SynapsePrefetch::all ? filterGIDs : GIDSet( )) , _afferent( afferent ) , _size( 0 ) { - if( prefetch == SYNAPSEPREFETCH_NONE ) + if( prefetch == SynapsePrefetch::none ) { _loadConnectivity( gids, filterGIDs ); return; } - if( prefetch & SYNAPSEPREFETCH_ATTRIBUTES ) + if( int( prefetch ) & int( SynapsePrefetch::attributes )) _loadAttributes( gids, filterGIDs ); - if( prefetch & SYNAPSEPREFETCH_POSITIONS ) + if( int( prefetch ) & int( SynapsePrefetch::positions )) _loadPositions( gids, filterGIDs ); } @@ -358,10 +358,10 @@ struct Synapses::Impl mutable lunchbox::Lock _lock; }; -Synapses::Synapses( const Circuit& circuit, const GIDSet& preGIDs, - const GIDSet& postGIDs, const bool afferent, +Synapses::Synapses( const Circuit& circuit, const GIDSet& pre, + const GIDSet& post, const bool afferent, const SynapsePrefetch prefetch ) - : _impl( new Impl( circuit, preGIDs, postGIDs, afferent, prefetch )) + : _impl( new Impl( circuit, pre, post, afferent, prefetch )) { } @@ -426,7 +426,7 @@ Synapse Synapses::operator[]( const size_t index_ ) const return Synapse( *this, index_ ); } -const size_t* Synapses::index() const +const size_t* Synapses::indices() const { lunchbox::ScopedRead mutex( _impl->_lock ); if( !_impl->_index ) @@ -434,161 +434,161 @@ const size_t* Synapses::index() const return _impl->_index.get(); } -const uint32_t* Synapses::preGID() const +const uint32_t* Synapses::preGIDs() const { return _impl->_preGID.get(); } -const uint32_t* Synapses::preSectionID() const +const uint32_t* Synapses::preSectionIDs() const { _impl->_ensureAttributes(); return _impl->_preSectionID.get(); } -const uint32_t* Synapses::preSegmentID() const +const uint32_t* Synapses::preSegmentIDs() const { _impl->_ensureAttributes(); return _impl->_preSegmentID.get(); } -const float* Synapses::preDistance() const +const float* Synapses::preDistances() const { _impl->_ensureAttributes(); return _impl->_preDistance.get(); } -const float* Synapses::preSurfacePositionX() const +const float* Synapses::preSurfaceXPositions() const { _impl->_ensurePositions(); return _impl->_preSurfacePositionX.get(); } -const float* Synapses::preSurfacePositionY() const +const float* Synapses::preSurfaceYPositions() const { _impl->_ensurePositions(); return _impl->_preSurfacePositionY.get(); } -const float* Synapses::preSurfacePositionZ() const +const float* Synapses::preSurfaceZPositions() const { _impl->_ensurePositions(); return _impl->_preSurfacePositionZ.get(); } -const float* Synapses::preCenterPositionX() const +const float* Synapses::preCenterXPositions() const { _impl->_ensurePositions(); return _impl->_preCenterPositionX.get(); } -const float* Synapses::preCenterPositionY() const +const float* Synapses::preCenterYPositions() const { _impl->_ensurePositions(); return _impl->_preCenterPositionY.get(); } -const float* Synapses::preCenterPositionZ() const +const float* Synapses::preCenterZPositions() const { _impl->_ensurePositions(); return _impl->_preCenterPositionZ.get(); } -const uint32_t* Synapses::postGID() const +const uint32_t* Synapses::postGIDs() const { return _impl->_postGID.get(); } -const uint32_t* Synapses::postSectionID() const +const uint32_t* Synapses::postSectionIDs() const { _impl->_ensureAttributes(); return _impl->_postSectionID.get(); } -const uint32_t* Synapses::postSegmentID() const +const uint32_t* Synapses::postSegmentIDs() const { _impl->_ensureAttributes(); return _impl->_postSegmentID.get(); } -const float* Synapses::postDistance() const +const float* Synapses::postDistances() const { _impl->_ensureAttributes(); return _impl->_postDistance.get(); } -const float* Synapses::postSurfacePositionX() const +const float* Synapses::postSurfaceXPositions() const { _impl->_ensurePositions(); return _impl->_postSurfacePositionX.get(); } -const float* Synapses::postSurfacePositionY() const +const float* Synapses::postSurfaceYPositions() const { _impl->_ensurePositions(); return _impl->_postSurfacePositionY.get(); } -const float* Synapses::postSurfacePositionZ() const +const float* Synapses::postSurfaceZPositions() const { _impl->_ensurePositions(); return _impl->_postSurfacePositionZ.get(); } -const float* Synapses::postCenterPositionX() const +const float* Synapses::postCenterXPositions() const { _impl->_ensurePositions(); return _impl->_postCenterPositionX.get(); } -const float* Synapses::postCenterPositionY() const +const float* Synapses::postCenterYPositions() const { _impl->_ensurePositions(); return _impl->_postCenterPositionY.get(); } -const float* Synapses::postCenterPositionZ() const +const float* Synapses::postCenterZPositions() const { _impl->_ensurePositions(); return _impl->_postCenterPositionZ.get(); } -const float* Synapses::delay() const +const float* Synapses::delays() const { _impl->_ensureAttributes(); return _impl->_delay.get(); } -const float* Synapses::conductance() const +const float* Synapses::conductances() const { _impl->_ensureAttributes(); return _impl->_conductance.get(); } -const float* Synapses::utilization() const +const float* Synapses::utilizations() const { _impl->_ensureAttributes(); return _impl->_utilization.get(); } -const float* Synapses::depression() const +const float* Synapses::depressions() const { _impl->_ensureAttributes(); return _impl->_depression.get(); } -const float* Synapses::facilitation() const +const float* Synapses::facilitations() const { _impl->_ensureAttributes(); return _impl->_facilitation.get(); } -const float* Synapses::decay() const +const float* Synapses::decays() const { _impl->_ensureAttributes(); return _impl->_decay.get(); } -const int* Synapses::efficacy() const +const int* Synapses::efficacys() const { _impl->_ensureAttributes(); return _impl->_efficacy.get(); diff --git a/brain/synapses.h b/brain/synapses.h index 589cd28..e669af1 100644 --- a/brain/synapses.h +++ b/brain/synapses.h @@ -80,132 +80,132 @@ class Synapses * @throw std::runtime_error if index information not found in the synapse * source of the circuit. */ - BRAIN_API const size_t* index() const; + BRAIN_API const size_t* indices() const; /** @name Presynaptic topological and geometrical attributes */ //@{ /** @return the GIDs of the presynaptic neurons. */ - BRAIN_API const uint32_t* preGID() const; + BRAIN_API const uint32_t* preGIDs() const; /** @return the section IDs on the presynaptic neurons. */ - BRAIN_API const uint32_t* preSectionID() const; + BRAIN_API const uint32_t* preSectionIDs() const; /** @return the segment IDs on the presynaptic neurons. */ - BRAIN_API const uint32_t* preSegmentID() const; + BRAIN_API const uint32_t* preSegmentIDs() const; /** @return the distances in micrometer to the presynaptic neurons. */ - BRAIN_API const float* preDistance() const; + BRAIN_API const float* preDistances() const; /** * @return the presynaptic touch position x-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* preSurfacePositionX() const; + BRAIN_API const float* preSurfaceXPositions() const; /** * @return the presynaptic touch position y-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* preSurfacePositionY() const; + BRAIN_API const float* preSurfaceYPositions() const; /** * @return the presynaptic touch position z-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* preSurfacePositionZ() const; + BRAIN_API const float* preSurfaceZPositions() const; /** * @return the presynaptic touch position x-coordinates in the center of the * segments. */ - BRAIN_API const float* preCenterPositionX() const; + BRAIN_API const float* preCenterXPositions() const; /** * @return the presynaptic touch position y-coordinates in the center of the * segments. */ - BRAIN_API const float* preCenterPositionY() const; + BRAIN_API const float* preCenterYPositions() const; /** * @return the presynaptic touch position z-coordinates in the center of the * segments. */ - BRAIN_API const float* preCenterPositionZ() const; + BRAIN_API const float* preCenterZPositions() const; //@} /** @name Presynaptic topological and geometrical attributes */ //@{ /** @return the GIDs of the postsynaptic neurons. */ - BRAIN_API const uint32_t* postGID() const; + BRAIN_API const uint32_t* postGIDs() const; /** @return the section IDs on the postsynaptic neurons. */ - BRAIN_API const uint32_t* postSectionID() const; + BRAIN_API const uint32_t* postSectionIDs() const; /** @return the segment IDs on the postsynaptic neurons. */ - BRAIN_API const uint32_t* postSegmentID() const; + BRAIN_API const uint32_t* postSegmentIDs() const; /** @return the distances in micrometer to the postsynaptic neurons. */ - BRAIN_API const float* postDistance() const; + BRAIN_API const float* postDistances() const; /** * @return the postsynaptic touch position x-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* postSurfacePositionX() const; + BRAIN_API const float* postSurfaceXPositions() const; /** * @return the postsynaptic touch position x-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* postSurfacePositionY() const; + BRAIN_API const float* postSurfaceYPositions() const; /** * @return the postsynaptic touch position x-coordinates on the surfaces of * the segments. */ - BRAIN_API const float* postSurfacePositionZ() const; + BRAIN_API const float* postSurfaceZPositions() const; /** * @return the postsynaptic touch position x-coordinates in the center of * the segments. */ - BRAIN_API const float* postCenterPositionX() const; + BRAIN_API const float* postCenterXPositions() const; /** * @return the postsynaptic touch position y-coordinates in the center of * the segments. */ - BRAIN_API const float* postCenterPositionY() const; + BRAIN_API const float* postCenterYPositions() const; /** * @return the postsynaptic touch position z-coordinates in the center of * the segments. */ - BRAIN_API const float* postCenterPositionZ() const; + BRAIN_API const float* postCenterZPositions() const; //@} /** @name Synaptic model attributes */ //@{ /** @return the axonal delays in milliseconds. */ - BRAIN_API const float* delay() const; + BRAIN_API const float* delays() const; /** @return the conductances in nanosiemens. */ - BRAIN_API const float* conductance() const; + BRAIN_API const float* conductances() const; /** @return the neuro-transmitter release probabilities. */ - BRAIN_API const float* utilization() const; + BRAIN_API const float* utilizations() const; /** @return the depression time constants in milliseconds. */ - BRAIN_API const float* depression() const; + BRAIN_API const float* depressions() const; /** @return the facilitation time constants in milliseconds. */ - BRAIN_API const float* facilitation() const; + BRAIN_API const float* facilitations() const; /** @return the decay time constants in milliseconds. */ - BRAIN_API const float* decay() const; + BRAIN_API const float* decays() const; /** @return the absolute synaptic efficacies in millivolts. */ - BRAIN_API const int* efficacy() const; + BRAIN_API const int* efficacys() const; //@} private: diff --git a/brain/types.h b/brain/types.h index dbc2df7..b7007f2 100644 --- a/brain/types.h +++ b/brain/types.h @@ -20,14 +20,25 @@ #ifndef BRAIN_TYPES #define BRAIN_TYPES -#include #include /** @namespace brain Algorithmic interface to Blue Brain data model */ namespace brain { -using namespace brain::enums; +/** + * Loading of data during SynapsesStream::read(), otherwise load happens + * on-demand. + */ +enum class SynapsePrefetch +{ + none = 0, //!< only loads pre- and post GIDs + attributes = 1 << 0, //!< topological information (section, + //! segment, distance) and model + //! attributes + positions = 1 << 1, //!< pre/post surface/center positions + all = attributes | positions //!< all synapse data +}; class Circuit; class Spikes; @@ -45,7 +56,6 @@ using vmml::Vector3f; using vmml::Vector4f; using brion::GIDSet; -using brion::SectionTypes; using brion::Strings; using brion::URI; using brion::URIs; diff --git a/doc/Changelog.md b/doc/Changelog.md index 02080e9..1ac5aa9 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,10 @@ Changelog {#Changelog} # Release 1.9.0 (git master) +* [88](https://github.com/BlueBrain/Brion/pull/88): + - Brain namespace enums made strongly typed. + - Fix for brain::Section::getSamples for sections where the first point + appears repeated. * [85](https://github.com/BlueBrain/Brion/pull/85): Implement brain synapses specification * [84](https://github.com/BlueBrain/Brion/pull/84): diff --git a/tests/brain/circuit.cpp b/tests/brain/circuit.cpp index 02558f6..9b139c4 100644 --- a/tests/brain/circuit.cpp +++ b/tests/brain/circuit.cpp @@ -251,9 +251,9 @@ BOOST_AUTO_TEST_CASE( test_gid_out_of_range ) BOOST_CHECK_THROW( circuit->getElectrophysiologyTypes( gids ), std::runtime_error ); BOOST_CHECK_THROW( circuit->getRotations( gids ), std::runtime_error ); - BOOST_CHECK_THROW( - circuit->loadMorphologies( gids, brain::Circuit::COORDINATES_LOCAL), - std::runtime_error ); + BOOST_CHECK_THROW( circuit->loadMorphologies( + gids, brain::Circuit::Coordinates::local), + std::runtime_error ); } } @@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE( load_local_morphologies ) gids.insert(gid); // This call also tests brain::Circuit::getMorphologyURIs const brain::neuron::Morphologies morphologies = - circuit.loadMorphologies( gids, brain::Circuit::COORDINATES_LOCAL ); + circuit.loadMorphologies( gids, brain::Circuit::Coordinates::local ); BOOST_CHECK_EQUAL( morphologies.size(), gids.size( )); // Checking the first morphology @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE( load_local_morphologies ) gids.insert(4); gids.insert(6); const brain::neuron::Morphologies repeated = - circuit.loadMorphologies( gids, brain::Circuit::COORDINATES_LOCAL ); + circuit.loadMorphologies( gids, brain::Circuit::Coordinates::local ); BOOST_CHECK_EQUAL( repeated.size(), gids.size( )); BOOST_CHECK_EQUAL( repeated[0].get(), repeated[2].get( )); @@ -293,7 +293,7 @@ BOOST_AUTO_TEST_CASE( load_global_morphologies ) for( uint32_t gid = 1; gid < 500; gid += 75) gids.insert(gid); const brain::neuron::Morphologies morphologies = - circuit.loadMorphologies( gids, brain::Circuit::COORDINATES_GLOBAL ); + circuit.loadMorphologies( gids, brain::Circuit::Coordinates::global ); BOOST_CHECK_EQUAL( morphologies.size(), gids.size( )); // Checking the first morphology diff --git a/tests/brain/morphology.cpp b/tests/brain/morphology.cpp index bb0eb11..9201aae 100644 --- a/tests/brain/morphology.cpp +++ b/tests/brain/morphology.cpp @@ -144,7 +144,9 @@ void checkEqualMorphologies( const brain::neuron::Morphology& first, first.getPoints( )); BOOST_CHECK( *second.readSections( brion::MORPHOLOGY_UNDEFINED ) == first.getSections( )); - BOOST_CHECK( *second.readSectionTypes() == first.getSectionTypes( )); + BOOST_CHECK( *second.readSectionTypes() == + reinterpret_cast< const brion::SectionTypes& >( + first.getSectionTypes( ))); BOOST_CHECK( *second.readApicals() == first.getApicals( )); } } // namespace @@ -167,26 +169,27 @@ BOOST_AUTO_TEST_CASE( v2_morphology_constructors ) BOOST_AUTO_TEST_CASE( get_section_ids ) { brain::neuron::Morphology morphology( TEST_MORPHOLOGY_URI ); + using brain::neuron::SectionType; - brion::SectionTypes types; - types.push_back( brion::SECTION_SOMA ); + brain::neuron::SectionTypes types{ SectionType::soma }; checkEqualArrays( morphology.getSectionIDs( types ), 1, 0 ); - types.push_back( brion::SECTION_DENDRITE ); + types.push_back( SectionType::dendrite ); checkEqualArrays( morphology.getSectionIDs( types ), 7, 0, 4, 5, 6, 7, 8, 9 ); - types.push_back( brion::SECTION_APICAL_DENDRITE ); + types.push_back( SectionType::apicalDendrite ); checkEqualArrays( morphology.getSectionIDs( types ), 10, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12 ); types.clear(); - types.push_back( brion::SECTION_AXON ); - types.push_back( brion::SECTION_DENDRITE ); + types.push_back( SectionType::axon ); + types.push_back( SectionType::dendrite ); checkEqualArrays( morphology.getSectionIDs( types ), 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 ); } BOOST_AUTO_TEST_CASE( get_sections ) { + using brain::neuron::SectionType; brain::neuron::Morphology morphology( TEST_MORPHOLOGY_URI ); BOOST_CHECK_THROW( morphology.getSection( 0 ), std::runtime_error ); @@ -201,14 +204,14 @@ BOOST_AUTO_TEST_CASE( get_sections ) BOOST_CHECK( section == morphology.getSection( 2 )); for( size_t i = 1; i < 4; ++i ) - BOOST_CHECK_EQUAL( morphology.getSection( i ).getType(), - brion::SECTION_AXON ); + BOOST_CHECK( morphology.getSection( i ).getType() == + SectionType::axon ); for( size_t i = 4; i < 10; ++i ) - BOOST_CHECK_EQUAL( morphology.getSection( i ).getType(), - brion::SECTION_DENDRITE ); + BOOST_CHECK( morphology.getSection( i ).getType() == + SectionType::dendrite ); for( size_t i = 10; i < 13; ++i ) - BOOST_CHECK_EQUAL( morphology.getSection( i ).getType(), - brion::SECTION_APICAL_DENDRITE ); + BOOST_CHECK( morphology.getSection( i ).getType() == + SectionType::apicalDendrite ); } BOOST_AUTO_TEST_CASE( get_section_samples ) diff --git a/tests/brain/synapses.cpp b/tests/brain/synapses.cpp index e2bb274..667f9d5 100644 --- a/tests/brain/synapses.cpp +++ b/tests/brain/synapses.cpp @@ -41,11 +41,11 @@ BOOST_AUTO_TEST_CASE( projection ) const brain::Synapses& syn1 = circuit.getProjectedSynapses( circuit.getGIDs( "Layer1" ), circuit.getGIDs( "Layer2" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); const brain::Synapses& syn2 = circuit.getProjectedSynapses( circuit.getGIDs( "Layer2" ), circuit.getGIDs( "Layer1" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); BOOST_CHECK_NE( syn1.size(), syn2.size( )); BOOST_CHECK_EQUAL( syn1.size(), 895 ); BOOST_CHECK_EQUAL( syn2.size(), 353 ); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( projection_stream ) brain::SynapsesStream stream = circuit.getProjectedSynapses( circuit.getGIDs( "Layer2" ), circuit.getGIDs( "Layer5" ), - brain::SYNAPSEPREFETCH_POSITIONS ); + brain::SynapsePrefetch::positions ); const size_t remaining = 130; BOOST_CHECK_EQUAL( stream.getRemaining(), remaining ); std::future< brain::Synapses > future = stream.read(); @@ -76,9 +76,9 @@ BOOST_AUTO_TEST_CASE( projection_stream ) ++i; BOOST_CHECK_EQUAL( stream.getRemaining(), remaining - i ); - const float* __restrict__ posx = synapses.preSurfacePositionX(); - const float* __restrict__ posy = synapses.preSurfacePositionY(); - const float* __restrict__ posz = synapses.preSurfacePositionZ(); + const float* __restrict__ posx = synapses.preSurfaceXPositions(); + const float* __restrict__ posy = synapses.preSurfaceYPositions(); + const float* __restrict__ posz = synapses.preSurfaceZPositions(); for( size_t j = 0; j < synapses.size(); ++j ) bbox.merge( vmml::Vector3f( posx[j], posy[j], posz[j] )); @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE( lazy_loading_afferent ) circuit.getAfferentSynapses( circuit.getGIDs( "Layer1" )); const brain::Synapses& synapsesLazy = circuit.getAfferentSynapses( circuit.getGIDs( "Layer1" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); BOOST_CHECK_EQUAL( synapses.size(), synapsesLazy.size() ); BOOST_CHECK_EQUAL( synapses[0].getPresynapticGID(), synapsesLazy[0].getPresynapticGID( )); @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE( lazy_loading_efferent ) circuit.getEfferentSynapses( circuit.getGIDs( "Layer1" )); const brain::Synapses& synapsesLazy = circuit.getEfferentSynapses( circuit.getGIDs( "Layer1" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); BOOST_CHECK_EQUAL( synapses.size(), synapsesLazy.size() ); BOOST_CHECK_EQUAL( synapses[0].getPresynapticGID(), synapsesLazy[0].getPresynapticGID( )); @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE( lazy_loading_pathway ) const brain::Synapses& synapsesLazy = circuit.getProjectedSynapses( circuit.getGIDs( "Layer2" ), circuit.getGIDs( "Layer4" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); BOOST_CHECK_EQUAL( synapses.size(), synapsesLazy.size() ); BOOST_CHECK_EQUAL( synapses[0].getPresynapticGID(), synapsesLazy[0].getPresynapticGID( )); @@ -196,7 +196,7 @@ BOOST_AUTO_TEST_CASE( copy ) const brain::Circuit circuit( brion::URI( BBP_TEST_BLUECONFIG3 )); const brain::Synapses& synapses = circuit.getAfferentSynapses( circuit.getGIDs( "Layer1" ), - brain::SYNAPSEPREFETCH_NONE ); + brain::SynapsePrefetch::none ); const brain::Synapses synapsesCopy = synapses; @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE( full_copy ) const brain::Circuit circuit( brion::URI( BBP_TEST_BLUECONFIG3 )); const brain::Synapses& synapses = circuit.getAfferentSynapses( circuit.getGIDs( "Layer1" ), - brain::SYNAPSEPREFETCH_ALL ); + brain::SynapsePrefetch::all ); const brain::Synapses synapsesCopy = synapses; @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE( check_all_synapse_attributes ) const brain::Circuit circuit( brion::URI( BBP_TEST_BLUECONFIG3 )); const brain::Synapses& synapses = circuit.getAfferentSynapses( brion::GIDSet{1}, - brain::SYNAPSEPREFETCH_ALL ); + brain::SynapsePrefetch::all ); BOOST_CHECK_EQUAL( synapses.size(), 77 ); const brain::Synapse& synapse = synapses[0];