~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/core/dataHandler/WFiberAccumulator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#include <fstream>
 
26
#include <string>
 
27
#include <vector>
 
28
 
 
29
#include "../common/WAssert.h"
 
30
 
 
31
#include "WFiberAccumulator.h"
 
32
 
 
33
WFiberAccumulator::WFiberAccumulator()
 
34
    : m_fiberMutex(),
 
35
      m_points( new std::vector< float >() ),
 
36
      m_fiberIndices( new std::vector< size_t >() ),
 
37
      m_fiberLengths( new std::vector< size_t >() ),
 
38
      m_pointToFiber( new std::vector< size_t >() )
 
39
{
 
40
}
 
41
 
 
42
WFiberAccumulator::~WFiberAccumulator()
 
43
{
 
44
}
 
45
 
 
46
void WFiberAccumulator::add( std::vector< WVector3d > const& in )
 
47
{
 
48
    boost::unique_lock< boost::mutex > lock( m_fiberMutex );
 
49
 
 
50
    if( in.size() > 0 )
 
51
    {
 
52
        m_fiberIndices->push_back( m_points->size() / 3 );
 
53
        m_fiberLengths->push_back( in.size() );
 
54
 
 
55
        for( size_t k = 0; k < in.size(); ++k )
 
56
        {
 
57
            m_points->push_back( in[ k ][ 0 ] );
 
58
            m_points->push_back( in[ k ][ 1 ] );
 
59
            m_points->push_back( in[ k ][ 2 ] );
 
60
 
 
61
            m_pointToFiber->push_back( m_fiberIndices->size() - 1 );
 
62
        }
 
63
    }
 
64
}
 
65
 
 
66
boost::shared_ptr< WDataSetFibers > WFiberAccumulator::buildDataSet()
 
67
{
 
68
    boost::unique_lock< boost::mutex > lock( m_fiberMutex );
 
69
 
 
70
    boost::shared_ptr< WDataSetFibers > res = boost::shared_ptr< WDataSetFibers >( new WDataSetFibers( m_points, m_fiberIndices,
 
71
                                                                                                       m_fiberLengths, m_pointToFiber ) );
 
72
 
 
73
    m_points = boost::shared_ptr< std::vector< float > >( new std::vector< float >() );
 
74
    m_fiberIndices = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
 
75
    m_fiberLengths = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
 
76
    m_pointToFiber = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
 
77
 
 
78
    return res;
 
79
}
 
80
 
 
81
void WFiberAccumulator::clear()
 
82
{
 
83
    m_points->clear();
 
84
    m_fiberIndices->clear();
 
85
    m_fiberLengths->clear();
 
86
    m_pointToFiber->clear();
 
87
}