OpenWalnut  1.4.0
WFiberAccumulator.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <fstream>
00026 #include <string>
00027 #include <vector>
00028 
00029 #include "../common/WAssert.h"
00030 
00031 #include "WFiberAccumulator.h"
00032 
00033 WFiberAccumulator::WFiberAccumulator()
00034     : m_fiberMutex(),
00035       m_points( new std::vector< float >() ),
00036       m_fiberIndices( new std::vector< size_t >() ),
00037       m_fiberLengths( new std::vector< size_t >() ),
00038       m_pointToFiber( new std::vector< size_t >() )
00039 {
00040 }
00041 
00042 WFiberAccumulator::~WFiberAccumulator()
00043 {
00044 }
00045 
00046 void WFiberAccumulator::add( std::vector< WVector3d > const& in )
00047 {
00048     boost::unique_lock< boost::mutex > lock( m_fiberMutex );
00049 
00050     if( in.size() > 0 )
00051     {
00052         m_fiberIndices->push_back( m_points->size() / 3 );
00053         m_fiberLengths->push_back( in.size() );
00054 
00055         for( size_t k = 0; k < in.size(); ++k )
00056         {
00057             m_points->push_back( in[ k ][ 0 ] );
00058             m_points->push_back( in[ k ][ 1 ] );
00059             m_points->push_back( in[ k ][ 2 ] );
00060 
00061             m_pointToFiber->push_back( m_fiberIndices->size() - 1 );
00062         }
00063     }
00064 }
00065 
00066 boost::shared_ptr< WDataSetFibers > WFiberAccumulator::buildDataSet()
00067 {
00068     boost::unique_lock< boost::mutex > lock( m_fiberMutex );
00069 
00070     boost::shared_ptr< WDataSetFibers > res( new WDataSetFibers( m_points, m_fiberIndices, m_fiberLengths, m_pointToFiber ) );
00071 
00072     m_points = boost::shared_ptr< std::vector< float > >( new std::vector< float >() );
00073     m_fiberIndices = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
00074     m_fiberLengths = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
00075     m_pointToFiber = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
00076 
00077     return res;
00078 }
00079 
00080 void WFiberAccumulator::clear()
00081 {
00082     m_points->clear();
00083     m_fiberIndices->clear();
00084     m_fiberLengths->clear();
00085     m_pointToFiber->clear();
00086 }