OpenWalnut  1.5.0dev
WConnectorData.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 <algorithm>
26 #include <vector>
27 
28 #include "WConnectorData.h"
29 
30 
32 {
33  m_vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array() );
34  m_colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array() );
35  m_edeps = std::shared_ptr< std::vector< float > >( new std::vector< float >() );
36  m_clusterSizes = std::shared_ptr< std::vector< float > >( new std::vector< float> () );
37 }
38 
40 {
41  m_vertices->clear();
42  m_colors->clear();
43  m_edeps->clear();
44  m_clusterSizes->clear();
45  m_hasClusterSize = false;
46 }
47 
48 osg::ref_ptr< osg::Vec3Array > WConnectorData::getVertices()
49 {
50  return m_vertices;
51 }
52 
53 osg::ref_ptr< osg::Vec4Array > WConnectorData::getColors()
54 {
55  return m_colors;
56 }
57 
58 std::shared_ptr< std::vector< float > > WConnectorData::getEdeps()
59 {
60  return m_edeps;
61 }
62 
63 std::shared_ptr< std::vector< float > > WConnectorData::getClusterSizes()
64 {
65  return m_clusterSizes;
66 }
67 
68 
69 void WConnectorData::addVertex( osg::Vec3 vertex, osg::Vec4 color, float edep, float clusterSize )
70 {
71  m_vertices->push_back( vertex );
72  m_colors->push_back( color );
73  m_edeps->push_back( edep );
74  m_clusterSizes->push_back( clusterSize );
75 }
76 
78 {
79  m_hasSelected = false;
80 }
81 
82 void WConnectorData::selectPoint( size_t idx )
83 {
84  m_selectedIndex = idx;
85  m_hasSelected = true;
86 }
87 
88 void WConnectorData::selectPoint( osg::Vec3 vertex )
89 {
90  std::vector< osg::Vec3 >::iterator vertexIterator = std::find( m_vertices->begin(), m_vertices->end(), vertex );
91  size_t vIdx = std::distance( m_vertices->begin(), vertexIterator );
92 
93  selectPoint( vIdx );
94 }
95 
97 {
98  *idx = m_selectedIndex;
99  return m_hasSelected;
100 }
101 
102 
104 {
105  return m_hasClusterSize;
106 }
107 
108 void WConnectorData::setHasClusterSize( bool clusterSize )
109 {
110  m_hasClusterSize = clusterSize;
111 }
bool getSelectedPoint(size_t *idx)
void deselectPoint()
Deselects the currently selected point.
void addVertex(osg::Vec3 vertex, osg::Vec4 color, float edep=0.0, float clusterSize=0.0)
Adds a vertex with its color to the currently selected fiber.
void selectPoint(size_t idx)
Selects a point by its index in m_vertices.
WConnectorData()
Creates the internal vector arrays.
std::shared_ptr< std::vector< float > > m_clusterSizes
The cluster size of the vertices.
bool m_hasClusterSize
Whether cluster size should be used.
void setHasClusterSize(bool clusterSize=true)
Sets whether the cluster size should be used.
std::shared_ptr< std::vector< float > > getEdeps()
void clear()
Clears the internal vector arrays.
bool m_hasSelected
Whether a selection has been done or not.
std::shared_ptr< std::vector< float > > m_edeps
The energy deposition of the vertices.
osg::ref_ptr< osg::Vec3Array > m_vertices
The vertices that are drawn.
std::shared_ptr< std::vector< float > > getClusterSizes()
size_t m_selectedIndex
The index of the selected vertex.
osg::ref_ptr< osg::Vec4Array > getColors()
osg::ref_ptr< osg::Vec3Array > getVertices()
osg::ref_ptr< osg::Vec4Array > m_colors
The color of the vertices that are drawn.