OpenWalnut  1.5.0dev
WFiberAccumulator.cpp
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 <memory>
27 #include <string>
28 #include <vector>
29 
30 #include "../common/WAssert.h"
31 #include "WFiberAccumulator.h"
32 
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 
43 {
44 }
45 
46 void WFiberAccumulator::add( std::vector< WVector3d > const& in )
47 {
48  std::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 std::shared_ptr< WDataSetFibers > WFiberAccumulator::buildDataSet()
67 {
68  std::unique_lock< boost::mutex > lock( m_fiberMutex );
69 
70  std::shared_ptr< WDataSetFibers > res( new WDataSetFibers( m_points, m_fiberIndices, m_fiberLengths, m_pointToFiber ) );
71 
72  m_points = std::shared_ptr< std::vector< float > >( new std::vector< float >() );
73  m_fiberIndices = std::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
74  m_fiberLengths = std::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
75  m_pointToFiber = std::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
76 
77  return res;
78 }
79 
81 {
82  m_points->clear();
83  m_fiberIndices->clear();
84  m_fiberLengths->clear();
85  m_pointToFiber->clear();
86 }
Represents a simple set of WFibers.
std::shared_ptr< std::vector< size_t > > m_fiberLengths
One of the vectors needed to construct a WDataSetFibers.
void add(std::vector< WVector3d > const &in)
Add a fiber to the dataset.
std::shared_ptr< WDataSetFibers > buildDataSet()
Return the dataset that has been accumulated to this point and start a new dataset.
boost::mutex m_fiberMutex
A mutex needed to guarantee thread-safety.
void clear()
Clears all data.
std::shared_ptr< std::vector< size_t > > m_fiberIndices
One of the vectors needed to construct a WDataSetFibers.
virtual ~WFiberAccumulator()
Destructor.
WFiberAccumulator()
Constructor.
std::shared_ptr< std::vector< float > > m_points
One of the vectors needed to construct a WDataSetFibers.
std::shared_ptr< std::vector< size_t > > m_pointToFiber
One of the vectors needed to construct a WDataSetFibers.