diff --git a/brain/circuit.cpp b/brain/circuit.cpp index 95e48a0..3e340ed 100644 --- a/brain/circuit.cpp +++ b/brain/circuit.cpp @@ -91,6 +91,13 @@ Quaternionf toQuaternion( #endif std::string toString( const std::string& in ) { return in; } +#ifdef BRION_USE_CXX03 +size_t toSize_t( const std::string& in ) + { return boost::lexical_cast< size_t >( in ); } +#else +size_t toSize_t( const std::string& in ) { return std::stoul( in ); } +#endif +size_t nop( const size_t& in ) { return in; } } class Circuit::Impl @@ -124,6 +131,10 @@ class Circuit::Impl } virtual Vector3fs getPositions( const GIDSet& gids ) const = 0; + virtual size_ts getMTypes( const GIDSet& gids ) const = 0; + virtual Strings getMorphologyNames() const = 0; + virtual size_ts getETypes( const GIDSet& gids ) const = 0; + virtual Strings getElectrophysiologyNames() const = 0; virtual Quaternionfs getRotations( const GIDSet& gids ) const = 0; virtual Strings getMorphologyNames( const GIDSet& gids ) const = 0; @@ -182,6 +193,40 @@ class MVD2 : public Circuit::Impl return positions; } + size_ts getMTypes( const GIDSet& gids ) const final + { + const brion::NeuronMatrix& matrix = _circuit.get( gids, + brion::NEURON_MTYPE ); + size_ts result( matrix.shape()[ 0 ]); + + brion::NeuronMatrix::const_array_view<1>::type view = + matrix[ boost::indices[brion::NeuronMatrix::index_range( )][ 0 ]]; + std::transform( view.begin(), view.end(), result.begin(), toSize_t ); + return result; + } + + Strings getMorphologyNames() const final + { + return _circuit.getTypes( brion::NEURONCLASS_MTYPE ); + } + + size_ts getETypes( const GIDSet& gids ) const final + { + const brion::NeuronMatrix& matrix = _circuit.get( gids, + brion::NEURON_ETYPE ); + size_ts result( matrix.shape()[ 0 ]); + + brion::NeuronMatrix::const_array_view<1>::type view = + matrix[ boost::indices[brion::NeuronMatrix::index_range( )][ 0 ]]; + std::transform( view.begin(), view.end(), result.begin(), toSize_t ); + return result; + } + + Strings getElectrophysiologyNames() const final + { + return _circuit.getTypes( brion::NEURONCLASS_ETYPE ); + } + Quaternionfs getRotations( const GIDSet& gids ) const final { const float deg2rad = float( M_PI ) / 180.f; @@ -211,14 +256,14 @@ class MVD2 : public Circuit::Impl Strings getMorphologyNames( const GIDSet& gids ) const final { - brion::NeuronMatrix matrix = - _circuit.get( gids, brion::NEURON_MORPHOLOGY_NAME ); - Strings res( matrix.shape()[ 0 ]); + const brion::NeuronMatrix& matrix = + _circuit.get( gids, brion::NEURON_MORPHOLOGY_NAME ); + Strings result( matrix.shape()[ 0 ]); - brion::NeuronMatrix::array_view<1>::type view = + brion::NeuronMatrix::const_array_view<1>::type view = matrix[ boost::indices[brion::NeuronMatrix::index_range( )][ 0 ]]; - std::transform( view.begin(), view.end(), res.begin(), toString ); - return res; + std::transform( view.begin(), view.end(), result.begin(), toString ); + return result; } private: @@ -248,6 +293,34 @@ class MVD3 : public Circuit::Impl return results; } + size_ts getMTypes( const GIDSet& gids ) const final + { + size_ts results( gids.size( )); + const ::MVD3::Range& range = getRange( gids ); + const size_ts& mtypes = _circuit.getIndexMtypes( range ); + assign( range, gids, mtypes, results, nop ); + return results; + } + + Strings getMorphologyNames() const final + { + return _circuit.listAllMtypes(); + } + + size_ts getETypes( const GIDSet& gids ) const final + { + size_ts results( gids.size( )); + const ::MVD3::Range& range = getRange( gids ); + const size_ts& etypes = _circuit.getIndexEtypes( range ); + assign( range, gids, etypes, results, nop ); + return results; + } + + Strings getElectrophysiologyNames() const final + { + return _circuit.listAllEtypes(); + } + Quaternionfs getRotations( const GIDSet& gids ) const final { Quaternionfs results( gids.size( )); @@ -361,6 +434,26 @@ Vector3fs Circuit::getPositions( const GIDSet& gids ) const return _impl->getPositions( gids ); } +size_ts Circuit::getMorphologyTypes( const GIDSet& gids ) const +{ + return _impl->getMTypes( gids ); +} + +Strings Circuit::getMorphologyNames() const +{ + return _impl->getMorphologyNames(); +} + +size_ts Circuit::getElectrophysiologyTypes( const GIDSet& gids ) const +{ + return _impl->getETypes( gids ); +} + +Strings Circuit::getElectrophysiologyNames() const +{ + return _impl->getElectrophysiologyNames(); +} + Matrix4fs Circuit::getTransforms( const GIDSet& gids ) const { const Vector3fs& positions = _impl->getPositions( gids ); diff --git a/brain/circuit.h b/brain/circuit.h index 2261762..4a12d88 100644 --- a/brain/circuit.h +++ b/brain/circuit.h @@ -85,6 +85,24 @@ class Circuit : public boost::noncopyable /** @return The positions of the given cells. */ BRAIN_API Vector3fs getPositions( const GIDSet& gids ) const; + /** @return The morphology type indices of the given cells. */ + BRAIN_API size_ts getMorphologyTypes( const GIDSet& gids ) const; + + /** + * @return The morphology type names of the circuit, indexed by + * getMorphologyTypes(). + */ + BRAIN_API Strings getMorphologyNames() const; + + /** @return The electrophysiology type indices of the given cells. */ + BRAIN_API size_ts getElectrophysiologyTypes( const GIDSet& gids ) const; + + /** + * @return The electrophysiology type names of the circuit, indexed by + * getElectrophysiologyTypes(). + */ + BRAIN_API Strings getElectrophysiologyNames() const; + /** @return The local to world transformations of the given cells. */ BRAIN_API Matrix4fs getTransforms( const GIDSet& gids ) const; /** @return The local to world rotation of the given cells. */ diff --git a/brain/types.h b/brain/types.h index 2309df1..7b17827 100644 --- a/brain/types.h +++ b/brain/types.h @@ -49,6 +49,7 @@ using brion::Vector3fs; using brion::Vector4fs; using brion::floats; using brion::uint32_ts; +using brion::size_ts; typedef std::vector< Matrix4f > Matrix4fs; typedef std::vector< Quaternionf > Quaternionfs; diff --git a/doc/Changelog.md b/doc/Changelog.md index b06be3e..57723d6 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,8 @@ Changelog {#Changelog} # git master +* [77](https://github.com/BlueBrain/Brion/pull/77): + Add brain::Circuit::getMorphologyTypes() and brain::Circuit::getElectrophysiologyTypes() * [75](https://github.com/BlueBrain/Brion/pull/75): Implement morphology version 1.1 specification * [74](https://github.com/BlueBrain/Brion/pull/74): diff --git a/tests/circuit.cpp b/tests/circuit.cpp index 39233a1..6405982 100644 --- a/tests/circuit.cpp +++ b/tests/circuit.cpp @@ -372,4 +372,40 @@ BOOST_AUTO_TEST_CASE(morphology_names_mvd3) "dend-ch160801B_axon-Fluo55_low.h5" )); } +BOOST_AUTO_TEST_CASE(compare_mvd2_mvd3) +{ + brion::BlueConfig config2( BBP_TEST_BLUECONFIG ); + brain::Circuit circuit2( config2 ); + + brion::BlueConfig config3( BBP_TEST_BLUECONFIG3 ); + brain::Circuit circuit3( config3 ); + + brion::GIDSet gids; + gids.insert( 21 ); + gids.insert( 501 ); + + const brain::size_ts& mtypes2 = circuit2.getMorphologyTypes( gids ); + const brain::size_ts& etypes2 = circuit2.getElectrophysiologyTypes( gids ); + const brain::Strings& allMTypes2 = circuit2.getMorphologyNames(); + const brain::Strings& allETypes2 = circuit2.getElectrophysiologyNames(); + const brain::URIs& names2 = circuit2.getMorphologyURIs( gids ); + + const brain::size_ts& mtypes3 = circuit3.getMorphologyTypes( gids ); + const brain::size_ts& etypes3 = circuit3.getElectrophysiologyTypes( gids ); + const brain::Strings& allMTypes3 = circuit3.getMorphologyNames(); + const brain::Strings& allETypes3 = circuit3.getElectrophysiologyNames(); + const brain::URIs& names3 = circuit3.getMorphologyURIs( gids ); + + BOOST_CHECK_EQUAL_COLLECTIONS( mtypes2.begin(), mtypes2.end(), + mtypes3.begin(), mtypes3.end( )); + BOOST_CHECK_EQUAL_COLLECTIONS( etypes2.begin(), etypes2.end(), + etypes3.begin(), etypes3.end( )); + BOOST_CHECK_EQUAL_COLLECTIONS( allMTypes2.begin(), allMTypes2.end(), + allMTypes3.begin(), allMTypes3.end( )); + BOOST_CHECK_EQUAL_COLLECTIONS( allETypes2.begin(), allETypes2.end(), + allETypes3.begin(), allETypes3.end( )); + BOOST_CHECK_EQUAL_COLLECTIONS( names2.begin(), names2.end(), + names3.begin(), names3.end( )); +} + #endif