WSelectionManager.cpp 4.09 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
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------

25 26 27 28 29 30 31
#include <vector>

#include <osg/Matrix>

#include "WKernel.h"
#include "../common/math/WLinearAlgebraFunctions.h"

32 33
#include "../graphicsEngine/WGEZoomTrackballManipulator.h"

schurade's avatar
schurade committed
34 35
#include "WSelectionManager.h"

36 37 38 39 40
using wmath::WVector3D;
using wmath::WPosition;
using wmath::WMatrix;


41
WSelectionManager::WSelectionManager() :
42 43 44
    m_paintMode( PAINTMODE_NONE ),
    m_textureOpacity( 1.0 ),
    m_useTexture( false )
schurade's avatar
schurade committed
45 46 47 48 49 50 51 52 53 54 55 56
{
    m_crosshair = boost::shared_ptr< WCrosshair >( new WCrosshair() );
}

WSelectionManager::~WSelectionManager()
{
}

boost::shared_ptr< WCrosshair >WSelectionManager::getCrosshair()
{
    return m_crosshair;
}
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

int WSelectionManager::getFrontSector()
{
    boost::shared_ptr< WGEViewer > viewer;
    viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
    viewer->getCamera()->getViewMatrix();
    osg::Matrix rm = viewer->getCamera()->getViewMatrix();

    WMatrix< double > rotMat( 4, 4 );
    for( size_t i = 0; i < 4; ++i )
    {
        for( size_t j = 0; j < 4; ++j )
        {
            rotMat( i, j ) = rm( i, j );
        }
    }
    WPosition v1( 0, 0, 1 );
    WPosition view;
    view = transformPosition3DWithMatrix4D( rotMat, v1 );

    std::vector<float> dots( 8 );
    WPosition v2( 1, 1, 1 );
    dots[0] = v2.dotProduct( view );

    v2[2] = -1;
    dots[1] = v2.dotProduct( view );

    v2[1] = -1;
    dots[2] = v2.dotProduct( view );

    v2[2] = 1;
    dots[3] = v2.dotProduct( view );

    v2[0] = -1;
    dots[4] = v2.dotProduct( view );

    v2[2] = -1;
    dots[5] = v2.dotProduct( view );

    v2[1] = 1;
    dots[6] = v2.dotProduct( view );

    v2[2] = 1;
    dots[7] = v2.dotProduct( view );

    float max = 0.0;
    int quadrant = 0;
    for ( int i = 0; i < 8; ++i )
    {
        if ( dots[i] > max )
        {
            max = dots[i];
            quadrant = i;
        }
    }
    return quadrant;
}
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

void WSelectionManager::setPaintMode( WPaintMode mode )
{
    m_paintMode = mode;

    osg::static_pointer_cast<WGEZoomTrackballManipulator>(
            WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode );
    WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode );
}

WPaintMode WSelectionManager::getPaintMode()
{
    return m_paintMode;
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
void WSelectionManager::setTexture( osg::ref_ptr< osg::Texture3D > texture, boost::shared_ptr< WGridRegular3D >grid )
{
    m_texture = texture;
    m_textureGrid = grid;
}


osg::ref_ptr< osg::Texture3D > WSelectionManager::getTexture()
{
    return m_texture;
}

boost::shared_ptr< WGridRegular3D >WSelectionManager::getGrid()
{
    return m_textureGrid;
}

void WSelectionManager::setUseTexture( bool flag )
{
    m_useTexture = flag;
}

bool WSelectionManager::getUseTexture()
{
    return m_useTexture;
}


float WSelectionManager::getTextureOpacity()
{
    return m_textureOpacity;
}

void WSelectionManager::setTextureOpacity( float value )
{
    if ( value < 0.0 )
    {
        value = 0.0;
    }
    if ( value > 1.0 )
    {
        value = 1.0;
    }
    m_textureOpacity = value;
}