WMLIC.cpp 3.14 KB
Newer Older
Mathias Goldau's avatar
Mathias Goldau 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 34 35 36 37 38 39 40 41 42 43 44 45 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 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
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------

#include <string>

#include "../../kernel/WKernel.h"
#include "WMLIC.h"

WMLIC::WMLIC():
    WModule()
{
}

WMLIC::~WMLIC()
{
    // Cleanup!
}

boost::shared_ptr< WModule > WMLIC::factory() const
{
    return boost::shared_ptr< WModule >( new WMLIC() );
}

const std::string WMLIC::getName() const
{
    return "LIC";
}

const std::string WMLIC::getDescription() const
{
    return "Line integrate convolution on TriangleMesh with a WDataSetVector";
}

void WMLIC::connectors()
{
    m_meshIC = boost::shared_ptr< WModuleInputData < WTriangleMesh2 > >(
            new WModuleInputData< WTriangleMesh2 >( shared_from_this(),
                "inMesh", "The triangle mesh used for painting the LIC" )
            );
    m_vectorIC = boost::shared_ptr< WModuleInputData < WDataSetVector > >(
            new WModuleInputData< WDataSetVector >( shared_from_this(),
                "inVectorDS", "The vectors used for computing the Streamlines used for the LIC" )
            );
    m_meshOC = boost::shared_ptr< WModuleOutputData < WTriangleMesh2 > >(
            new WModuleOutputData< WTriangleMesh2 >( shared_from_this(),
                "outMesh", "The LIC" )
            );

    addConnector( m_meshIC );
    addConnector( m_vectorIC );
    addConnector( m_meshOC );
    WModule::connectors();
}

void WMLIC::properties()
{
}

void WMLIC::moduleMain()
{
    m_moduleState.setResetable( true, true );
    m_moduleState.add( m_meshIC->getDataChangedCondition() );
    m_moduleState.add( m_vectorIC->getDataChangedCondition() );

    ready();

    while ( !m_shutdownFlag() )
    {
        m_moduleState.wait();

        if ( m_shutdownFlag() )
        {
            break;
        }

        boost::shared_ptr< WTriangleMesh2 > newMesh = m_meshIC->getData();
        boost::shared_ptr< WDataSetVector > newVector = m_vectorIC->getData();
        bool dataChanged = ( m_inMesh != newMesh ) || ( m_inVector != newVector );
        bool dataValid   = ( newMesh.get() && newVector.get() );

        if ( dataChanged && dataValid )
        {
            debugLog() << "Received Data.";
            m_inMesh = newMesh;
            m_inVector = newVector;
        }
    }
}