WSelectorBranch.h 3.77 KB
Newer Older
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
//---------------------------------------------------------------------------
//
// 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 WSELECTORBRANCH_H
#define WSELECTORBRANCH_H

#include <list>
#include <vector>

#include "WSelectorRoi.h"
32
#include "../kernel/WRMBranch.h"
33 34 35 36 37 38 39 40 41

/**
 * TODO(schurade): Document this!
 */
class WSelectorBranch
{
public:
    /**
     * constructor
42
     * \param fibers pointer to the fiber dataset to work on
43 44
     * \param branch pointer to the branch object in the roi manager
     */
45
    WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr<WRMBranch> branch );
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    /**
     * destructor
     */
    ~WSelectorBranch();

    /**
     * getter
     * \return the bitfield that is created from all rois in this branch
     */
    boost::shared_ptr< std::vector<bool> >getBitField();

    /**
     * getter
     * \return pointer to the branch object, mainly for deletion and update purposes
     */
    boost::shared_ptr<WRMBranch> getBranch();

    /**
     * adds a roi to the branch
     * \param roi
     */
    void addRoi( boost::shared_ptr< WSelectorRoi> roi );

    /**
     * removes a roi fromt he branch
     * \param roi
     */
    void removeRoi( osg::ref_ptr< WROI > roi );

    /**
     * getter
     * \return true when this branch contains no rois
     */
    bool empty();

82 83 84 85 86 87
    /**
     * setter
     * sets the dirty flag
     */
    void setDirty();

88 89 90 91 92
    /**
     * getter
     */
    bool dirty();

93
protected:
94 95 96 97 98
    /**
     * function gets called when the color property of the roi branch has changed, it will write this color
     * into the custom color array of the fiber dataset
     */
    void colorChanged();
99 100 101 102 103 104
private:
    /**
     * updates the output bitfield with the information from all rois in this branch
     */
    void recalculate();

105 106 107 108 109
    /**
     * Pointer to the fiber data set
     */
    boost::shared_ptr< const WDataSetFibers > m_fibers;

110 111 112 113 114
    /**
     * size of the fiber dataset, stored for convinience
     */
    size_t m_size;

115 116
    bool m_dirty; //!< dirty flag

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    /**
     * the bitfield given to the outside world
     */
    boost::shared_ptr< std::vector<bool> >m_bitField;

    /**
     * the bitfield we work on
     */
    boost::shared_ptr< std::vector<bool> >m_workerBitfield;

    /**
     * list of rois in this branch
     */
    std::list< boost::shared_ptr<WSelectorRoi> >m_rois;

    /**
     * pointer to the branch object in the roi manager
     */
    boost::shared_ptr<WRMBranch> m_branch;
};

inline boost::shared_ptr< std::vector<bool> > WSelectorBranch::getBitField()
{
140
    if ( m_dirty )
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    {
        recalculate();
    }
    return m_bitField;
}

inline boost::shared_ptr<WRMBranch> WSelectorBranch::getBranch()
{
    return m_branch;
}

inline bool WSelectorBranch::empty()
{
    return m_rois.empty();
}

157 158 159 160 161
inline bool WSelectorBranch::dirty()
{
    return m_dirty;
}

162
#endif  // WSELECTORBRANCH_H