WRMBranch.h 6.75 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
//---------------------------------------------------------------------------
//
// 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 WRMBRANCH_H
#define WRMBRANCH_H

#include <list>
schurade's avatar
[STYLE]  
schurade committed
29
#include <string>
schurade's avatar
schurade committed
30 31 32 33
#include <vector>

#include <boost/enable_shared_from_this.hpp>

34
#include "../common/WProperties.h"
schurade's avatar
schurade committed
35

36
#include "../graphicsEngine/WROI.h"
37

38
class WROIManager;
schurade's avatar
schurade committed
39 40

/**
schurade's avatar
[DOC]  
schurade committed
41
 * implements a branch in the tree like structure for rois
schurade's avatar
schurade committed
42
 */
43
class  WRMBranch : public boost::enable_shared_from_this< WRMBranch >
schurade's avatar
schurade committed
44 45
{
public:
46 47 48 49 50 51 52 53 54 55
    /**
     * Convenience type for a shared pointer of this type
     */
    typedef boost::shared_ptr< WRMBranch > SPtr;

    /**
     * Convenience type for a const shared pointer of this type
     */
    typedef boost::shared_ptr< const WRMBranch > ConstSPtr;

schurade's avatar
schurade committed
56
    /**
schurade's avatar
[DOC]  
schurade committed
57 58
     * construtor
     * \param roiManager
schurade's avatar
schurade committed
59
     */
60
    explicit WRMBranch( boost::shared_ptr< WROIManager > roiManager );
schurade's avatar
schurade committed
61 62

    /**
schurade's avatar
[DOC]  
schurade committed
63
     * destructor
schurade's avatar
schurade committed
64 65 66
     */
    ~WRMBranch();

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    /**
     * Get name property.
     *
     * \return  name property
     */
    WPropString nameProperty();

    /**
     * Get the "not" property.
     *
     * \return the property
     */
    WPropBool invertProperty();

    /**
     * The branch color property.
     *
     * \return the color property
     */
    WPropColor colorProperty();

88 89 90 91 92 93 94
    /**
     * Get the properties of this branch as group.
     *
     * \return branch property group
     */
    WPropertyGroup::SPtr getProperties() const;

schurade's avatar
schurade committed
95
    /**
schurade's avatar
[DOC]  
schurade committed
96
     * adds a roi to the branch
schurade's avatar
schurade committed
97
     *
schurade's avatar
[DOC]  
schurade committed
98
     * \param roi
schurade's avatar
schurade committed
99
     */
100
    void addRoi( osg::ref_ptr< WROI > roi );
schurade's avatar
schurade committed
101

schurade's avatar
schurade committed
102 103 104 105 106
    /**
     * removes a roi from the branch
     *
     * \param roi
     */
107
    void removeRoi( osg::ref_ptr< WROI > roi );
schurade's avatar
schurade committed
108 109 110 111 112 113 114

    /**
     * removes all rois from the branch
     *
     */
    void removeAllRois();

schurade's avatar
schurade committed
115 116
    /**
     * getter for dirty flag
schurade's avatar
[DOC]  
schurade committed
117
     *
118
     * \param reset when true the dirty flag will be set to false
schurade's avatar
[DOC]  
schurade committed
119
     * \return the dirty flag
schurade's avatar
schurade committed
120
     */
121
    bool dirty( bool reset = false );
schurade's avatar
schurade committed
122 123 124 125 126 127

    /**
     * sets dirty flag true and notifies the branch
     */
    void setDirty();

schurade's avatar
schurade committed
128
    /**
129 130 131
     * returns whether the branch is empty.
     *
     * \return true if empty.
schurade's avatar
schurade committed
132
     */
133
    bool empty();
schurade's avatar
schurade committed
134

135 136 137 138 139 140 141
    /**
     * checks wether a roi is in this branch
     * \param roi
     * \return true if the roi is in the branch, false otherwise
     */
    bool contains( osg::ref_ptr< WROI > roi );

schurade's avatar
schurade committed
142 143
    /**
     * returns a pointer to the first roi in the branch
schurade's avatar
[DOC]  
schurade committed
144 145
     *
     * \return the roi
schurade's avatar
schurade committed
146
     */
147
    osg::ref_ptr< WROI > getFirstRoi();
schurade's avatar
schurade committed
148 149

    /**
schurade's avatar
[DOC]  
schurade committed
150
     * getter for roi manager pointer
schurade's avatar
schurade committed
151
     *
schurade's avatar
[DOC]  
schurade committed
152
     * \return the roi manager
schurade's avatar
schurade committed
153
     */
154
    boost::shared_ptr< WROIManager > getRoiManager();
schurade's avatar
schurade committed
155

schurade's avatar
schurade committed
156
    /**
157 158 159
     * returns the properties object.
     *
     * \return the properties of this branch
schurade's avatar
schurade committed
160
     */
161
    boost::shared_ptr< WProperties > getProperties();
schurade's avatar
schurade committed
162

163 164 165 166 167 168
    /**
     * getter for the NOT flag
     * \return flag
     */
    bool isNot();

169 170 171 172 173
    /**
     * add all the rois in this branch to a given vector
     * \param roiVec the vector to fill
     */
    void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
schurade's avatar
schurade committed
174

175 176 177 178 179 180 181
    /**
     * Create a list of ROIs of the current point in time.
     *
     * \return the ROIs
     */
    std::vector< osg::ref_ptr< WROI > > getRois() const;

182 183 184 185 186
    /**
     * Add a specified notifier to the list of default notifiers which get connected to each branch
     *
     * \param notifier  the notifier function
     */
187 188 189 190 191 192 193 194
    void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );

    /**
     * Remove a specified notifier from the list of default notifiers which get connected to each branch
     *
     * \param notifier  the notifier function
     */
    void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
195

196 197 198 199 200 201 202 203 204 205
    /**
     * Resorts the ROIs using the specified comparator from its begin to its end.
     *
     * \tparam Comparator the comparator type. Usually a boost::function or class providing the operator<().
     *
     * \param comp the comparator
     */
    template < typename Comparator >
    void sort( Comparator comp );

schurade's avatar
schurade committed
206
protected:
schurade's avatar
schurade committed
207
    /**
208
     * initializes properties
schurade's avatar
schurade committed
209
     */
210
    void properties();
schurade's avatar
schurade committed
211

schurade's avatar
schurade committed
212 213 214 215
    /**
     * slot gets called when a property has changed
     *
     */
216
    void propertyChanged();
schurade's avatar
schurade committed
217
private:
218
    boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
219

220 221
    std::vector< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
                                                  // first in the list is the master roi
schurade's avatar
schurade committed
222 223 224
    /**
     * the property object for the module
     */
225
    boost::shared_ptr< WProperties > m_properties;
schurade's avatar
schurade committed
226

227 228
    WPropBool m_dirty; //!< dirty flag to indicate if anything has changed within the branch

schurade's avatar
schurade committed
229 230 231 232
    /**
     * indicates if the branch is negated
     */
    WPropBool m_isNot;
schurade's avatar
schurade committed
233 234 235 236 237

    /**
     * The color used when in isosurface mode for blending.
     */
    WPropColor m_bundleColor;
238

239 240 241 242 243
    /**
     * Name property.
     */
    WPropString m_name;

244 245 246
    /**
     * The notifiers connected to added rois by default.
     */
247 248 249
    std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers;

    boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the ROImanager branch
250 251 252 253 254

    /**
     * Lock for associated notifiers set.
     */
    boost::shared_mutex m_associatedNotifiersLock;
schurade's avatar
schurade committed
255 256
};

257 258 259 260 261
inline bool WRMBranch::empty()
{
    return m_rois.empty();
}

262
inline bool WRMBranch::dirty( bool reset )
263
{
264
    bool ret = m_dirty->get();
265
    if( reset )
266 267 268 269
    {
        m_dirty->set( false );
    }
    return ret;
270 271
}

272 273 274 275
inline bool WRMBranch::isNot()
{
    return m_isNot->get();
}
276 277 278 279 280 281 282 283

template < typename Comparator >
void WRMBranch::sort( Comparator comp )
{
    // NOTE: technically, we need not setDirty here as the order of the ROIs has no influence
    return std::sort( m_rois.begin(), m_rois.end(), comp );
}

schurade's avatar
schurade committed
284
#endif  // WRMBRANCH_H