WROIManagerFibers.h 6.66 KB
Newer Older
schurade's avatar
schurade committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WROIMANAGERFIBERS_H
#define WROIMANAGERFIBERS_H

#include <list>
#include <vector>

#include <boost/enable_shared_from_this.hpp>

#include "WKdTree.h"
Mathias Goldau's avatar
Mathias Goldau committed
34
#include "WMFiberDisplay.h"
schurade's avatar
schurade committed
35 36

#include "WRMBranch.h"
37
#include "WUpdateThread.h"
schurade's avatar
schurade committed
38

39 40
#include "../../WExport_KernelDLL.h"

schurade's avatar
schurade committed
41 42 43
/**
 * Class to store and manage different ROI's for fiber selection
 */
44
class EXPORT_KERNEL_DLL WROIManagerFibers: public boost::enable_shared_from_this< WROIManagerFibers >
schurade's avatar
schurade committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
{
public:
    /**
     * standard constructor
     */
    WROIManagerFibers();

    /**
     * destructor
     */
    ~WROIManagerFibers();

    /**
     * adds a new master ROI
     *
     * \param newRoi
61
     * \return ROI representation which can be used to remove the ROI
schurade's avatar
schurade committed
62
     */
63
    boost::shared_ptr< WRMROIRepresentation > addRoi( osg::ref_ptr< WROI > newRoi );
schurade's avatar
schurade committed
64 65 66 67 68 69

    /**
     * adds a new ROI below a master ROI
     *
     * \param newRoi
     * \param parentRoi
70
     * \return ROI representation which can be used to remove the ROI
schurade's avatar
schurade committed
71
     */
72
    boost::shared_ptr< WRMROIRepresentation > addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
schurade's avatar
schurade committed
73 74 75 76 77 78

    /**
     * removes a roi
     *
     * \param roi
     */
schurade's avatar
schurade committed
79 80 81 82 83 84 85 86
    void removeRoi( boost::shared_ptr< WRMROIRepresentation > roi );

    /**
     * removes a branch
     *
     * \param roi the first roi in the branch
     */
    void removeBranch( boost::shared_ptr< WRMROIRepresentation > roi );
schurade's avatar
schurade committed
87 88 89 90 91 92

    /**
     * connects a fiber dataset to the roi manager
     *
     * \param fibers
     */
Mathias Goldau's avatar
Mathias Goldau committed
93
    void addFiberDataset( boost::shared_ptr< const WDataSetFibers > fibers );
schurade's avatar
schurade committed
94 95 96 97 98 99

    /**
     * removes a fiber dataset from the roi manager
     *
     * \param fibers
     */
Mathias Goldau's avatar
Mathias Goldau committed
100
    void removeFiberDataset( boost::shared_ptr< const WDataSetFibers > fibers );
schurade's avatar
schurade committed
101 102 103 104 105 106 107

    /**
     * returns a bit vector for the selected fiber dataset that is the result of all active ROI's
     * on that fiber dataset
     *
     * \return std::vector<bool>*
     */
schurade's avatar
schurade committed
108
    boost::shared_ptr< std::vector< bool > > getBitField();
schurade's avatar
schurade committed
109 110

    /**
schurade's avatar
[DOC]  
schurade committed
111
     * getter for a registered dataset
schurade's avatar
schurade committed
112
     *
schurade's avatar
[DOC]  
schurade committed
113
     * \return the dataset
schurade's avatar
schurade committed
114
     */
schurade's avatar
schurade committed
115
    boost::shared_ptr< const WDataSetFibers > getDataSet();
schurade's avatar
schurade committed
116 117

    /**
schurade's avatar
[DOC]  
schurade committed
118 119
     * getter for a kd tree
     * return the kd tree
schurade's avatar
schurade committed
120
     */
schurade's avatar
schurade committed
121
    boost::shared_ptr< WKdTree > getKdTree();
schurade's avatar
schurade committed
122 123

    /**
schurade's avatar
[DOC]  
schurade committed
124
     * adds a bit field list of bit fields
schurade's avatar
schurade committed
125
     *
schurade's avatar
[DOC]  
schurade committed
126
     * \param size
schurade's avatar
schurade committed
127 128 129 130
     */
    void addBitField( size_t size );

    /**
schurade's avatar
[DOC]  
schurade committed
131
     * sets the dirty flag which will cause recalculation of the bit field
schurade's avatar
schurade committed
132 133 134 135
     */
    void setDirty();

    /**
schurade's avatar
[DOC]  
schurade committed
136 137
     *  getter
     *  \return the dirty flag
schurade's avatar
schurade committed
138 139 140
     */
    bool isDirty();

schurade's avatar
schurade committed
141
    /**
142
     * Add a specified notifier to the list of default notifiers which get connected to each added roi.
schurade's avatar
schurade committed
143 144 145
     *
     * \param notifier  the notifier function
     */
146 147 148 149 150 151 152 153
    virtual void addAddNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier );

    /**
     * Add a specified notifier to the list of default notifiers which get connected to each removed roi.
     *
     * \param notifier  the notifier function
     */
    virtual void addRemoveNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier );
schurade's avatar
schurade committed
154

schurade's avatar
schurade committed
155
    /**
schurade's avatar
[DOC]  
schurade committed
156
     * updates the bit fields
schurade's avatar
schurade committed
157 158 159
     */
    void recalculate();

schurade's avatar
schurade committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    /**
     * creates a color array, that is used for coloring of fibers
     */
    void createCustomColorArray();

    /**
     * getter
     */
    boost::shared_ptr< std::vector< float > >getCustomColors();

    /**
     * updates the custom color array with the color of a selected branch
     *
     * \param branch
     * \param color
     */
    void updateBundleColor( boost::shared_ptr<WRMBranch> branch, WColor color );

178 179 180 181 182 183 184 185 186 187 188
    /**
     * setter
     * \param roi
     */
    void setSelectedRoi( boost::shared_ptr< WRMROIRepresentation > roi );

    /**
     * getter
     */
    boost::shared_ptr< WRMROIRepresentation > getSelectedRoi();

schurade's avatar
schurade committed
189 190
protected:
private:
schurade's avatar
[DOC]  
schurade committed
191
    bool m_dirty; //!< dirty flag
schurade's avatar
schurade committed
192

schurade's avatar
schurade committed
193 194 195 196
    int m_activeBitField; //!< indicates which bitfield is currently used for fiber selection

    boost::shared_ptr< const WDataSetFibers >m_fibers; //!< registered fiber dataset

197
    boost::shared_ptr< std::vector< bool > >m_bitField; //!< bit field of activated fibers
schurade's avatar
schurade committed
198

199
    boost::shared_ptr< std::vector< bool > >m_bitField2; //!< bit field of activated fibers
schurade's avatar
schurade committed
200

schurade's avatar
[DOC]  
schurade committed
201
    std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
schurade's avatar
schurade committed
202

203 204 205 206
    std::list< boost::shared_ptr< WUpdateThread > > m_updateThreads; //!< list ofcurrent update threads.

    boost::shared_mutex m_updateListLock; //!< Lock to prevent concurrent threads trying to update the list

schurade's avatar
schurade committed
207 208 209
    /**
     * Stores a pointer to the kdTree used for fiber selection
     */
210
    boost::shared_ptr< WKdTree > m_kdTree;
schurade's avatar
schurade committed
211

schurade's avatar
schurade committed
212 213 214 215 216 217 218 219
    /**
     * Lock for associated notifiers set.
     */
    boost::shared_mutex m_associatedNotifiersLock;

    /**
     * The notifiers connected to added rois by default.
     */
220 221 222 223 224 225
    std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > > m_addNotifiers;

    /**
     * The notifiers connected to removed rois by default.
     */
    std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > > m_removeNotifiers;
schurade's avatar
schurade committed
226 227 228 229 230 231 232 233 234 235

    /**
     * lock to prevent concurrent threads trying to update the branch
     */
    boost::shared_mutex m_updateLock;

    /**
     * bool to lock the update function, will be removed again once we found out why the boost lock isnt working
     */
    bool m_recalcLock;
schurade's avatar
schurade committed
236 237

    boost::shared_ptr< std::vector< float > >m_customColors; //!< vector to store custom colors
238 239

    boost::shared_ptr< WRMROIRepresentation > m_selectedRoi; //!< stores a pointer to the currently selected roi
schurade's avatar
schurade committed
240 241 242
};

#endif  // WROIMANAGERFIBERS_H