WMReadLAS.cpp 8.63 KB
Newer Older
1 2 3 4
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
5
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// 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>

27 28 29
#include <fstream>
#include <iostream>
#include <limits>
30 31 32 33 34 35 36 37 38 39 40 41 42 43

#include <osg/Geometry>
#include "core/kernel/WModule.h"

#include "core/dataHandler/WDataSetScalar.h"
#include "core/graphicsEngine/callbacks/WGELinearTranslationCallback.h"
#include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/graphicsEngine/WGEGeodeUtils.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/kernel/WKernel.h"
#include "core/kernel/WModuleInputData.h"
#include "WMReadLAS.xpm"
#include "WMReadLAS.h"
44
#include "WLasReader.h"
45 46 47 48 49

WMReadLAS::WMReadLAS():
    WModule(),
    m_propCondition( new WCondition() )
{
50
    reader = laslibb::WLasReader( m_progress );
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
}

WMReadLAS::~WMReadLAS()
{
}

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

const char** WMReadLAS::getXPMIcon() const
{
    return WMReadLAS_xpm;
}
66

67 68
const std::string WMReadLAS::getName() const
{
69
    return "Read LAS";
70 71 72 73 74 75 76 77 78 79 80
}

const std::string WMReadLAS::getDescription() const
{
    return "Should draw values above some threshold.";
}

void WMReadLAS::connectors()
{
    m_output = boost::shared_ptr< WModuleOutputData< WDataSetPoints > >(
                new WModuleOutputData< WDataSetPoints >(
81
                        shared_from_this(), "points", "The loaded points." ) );
82 83 84 85 86 87 88

    addConnector( m_output );
    WModule::connectors();
}

void WMReadLAS::properties()
{
89 90
    m_lasFile = m_properties->addProperty( "LiDAR file", "", WPathHelper::getAppPath() );
    WPropertyHelper::PC_PATHEXISTS::addTo( m_lasFile );
aschwarzkopf's avatar
aschwarzkopf committed
91

92 93
    m_reloadData = m_properties->addProperty( "Reload data:",  "Refresh", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );

94 95 96 97
    m_selectionRadius = m_properties->addProperty( "Selection radius: ",
                            "Outpt area size which is of the area radius*radius*4 meters^2.",
                            100.0, m_propCondition );
    m_selectionRadius->setMin( 0.0 );
aschwarzkopf's avatar
aschwarzkopf committed
98

Alexander Wiebel's avatar
Alexander Wiebel committed
99
    m_sliderX = m_properties->addProperty( "Scope selection X: ",
aschwarzkopf's avatar
aschwarzkopf committed
100
                            "X range will be drawn between input and input+'Data set "
101
                            "width'.", 0.0, m_propCondition );
aschwarzkopf's avatar
aschwarzkopf committed
102

Alexander Wiebel's avatar
Alexander Wiebel committed
103
    m_sliderY = m_properties->addProperty( "Scope selection Y: ",
104
                            "YY range will be drawn between input and input+'Data set "
105
                            "width'.", 0.0, m_propCondition );
aschwarzkopf's avatar
aschwarzkopf committed
106 107 108 109 110

    m_translateDataToCenter = m_properties->addProperty( "Translate to center: ",
                            "Translates X and Y coordinates to center. Minimal and maximal "
                            "possible coordinates are -/+'Data set width'/2."
                            ".", true, m_propCondition );
111 112 113

    m_colorsEnabled = m_properties->addProperty( "Colors enabled", "", true, m_propCondition );

114 115 116 117
    m_contrast = m_properties->addProperty( "Contrast: ",
                            "This is the value that multiplies the input colors before assigning to the output. "
                            "Note that the output has the range between 0.0 and 1.0.\r\nHint: Look ath the intensity "
                            "maximum param in the information tab of the ReadLAS plugin.", 0.005, m_propCondition );
aschwarzkopf's avatar
aschwarzkopf committed
118

119 120
    m_nbVertices = m_infoProperties->addProperty( "Points", "The number of vertices in the loaded scan.", 0 );
    m_nbVertices->setMax( std::numeric_limits< int >::max() );
121 122 123 124 125 126 127 128 129 130 131 132
    m_minCoord.push_back( m_infoProperties->addProperty( "X min.: ", "Minimal x coordinate of all input points.", 0.0 ) );
    m_maxCoord.push_back( m_infoProperties->addProperty( "X max.: ", "Maximal x coordinate of all input points.", 0.0 ) );
    m_minCoord.push_back( m_infoProperties->addProperty( "Y min.: ", "Minimal y coordinate of all input points.", 0.0 ) );
    m_maxCoord.push_back( m_infoProperties->addProperty( "Y max.: ", "Maximal y coordinate of all input points.", 0.0 ) );
    m_minCoord.push_back( m_infoProperties->addProperty( "Z min.: ", "Minimal z coordinate of all input points.", 0.0 ) );
    m_maxCoord.push_back( m_infoProperties->addProperty( "Z max.: ", "Maximal z coordinate of all input points.", 0.0 ) );
    m_colorMin.push_back( m_infoProperties->addProperty( "Red min.: ", "", 0.0 ) );
    m_colorMax.push_back( m_infoProperties->addProperty( "Red max.: ", "", 0.0 ) );
    m_colorMin.push_back( m_infoProperties->addProperty( "Green min.: ", "", 0.0 ) );
    m_colorMax.push_back( m_infoProperties->addProperty( "Green max.: ", "", 0.0 ) );
    m_colorMin.push_back( m_infoProperties->addProperty( "Blue min.: ", "", 0.0 ) );
    m_colorMax.push_back( m_infoProperties->addProperty( "Blue max.: ", "", 0.0 ) );
133 134
    m_intensityMin = m_infoProperties->addProperty( "Intensity min.: ", "Minimal intensity of all input points.", 0.0 );
    m_intensityMax = m_infoProperties->addProperty( "Intensity max.: ", "Maximal intensity of all input points.", 0.0 );
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
    WModule::properties();
}

void WMReadLAS::requirements()
{
}

void WMReadLAS::moduleMain()
{
    // get notified about data changes
    m_moduleState.setResetable( true, true );
    m_moduleState.add( m_propCondition );

    ready();

    // graphics setup
    m_rootNode = osg::ref_ptr< WGEManagedGroupNode >( new WGEManagedGroupNode( m_active ) );
    WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );



    // main loop
    while( !m_shutdownFlag() )
    {
        m_moduleState.wait();

aschwarzkopf's avatar
aschwarzkopf committed
162 163 164
        reader.setInputFilePath( m_lasFile->get().c_str() );
        try
        {
Alexander Wiebel's avatar
Alexander Wiebel committed
165 166
            reader.setDataSetRegion( m_sliderX->get( true ),
                                     m_sliderY->get( true ),
167 168
                                     m_selectionRadius->get( true ) );
            reader.setColorsEnabled( m_colorsEnabled->get() );
169
            reader.setTranslateToCenter( m_translateDataToCenter->get( true ) );
170
            reader.setContrast( m_contrast->get() );
171
            boost::shared_ptr< WDataSetPoints > tmpPointSet = reader.getPoints();
aschwarzkopf's avatar
aschwarzkopf committed
172 173
            WDataSetPoints::VertexArray points = tmpPointSet->getVertices();
            WDataSetPoints::ColorArray colors = tmpPointSet->getColors();
174
            m_nbVertices->set( tmpPointSet->size() );
175 176 177 178 179 180 181 182 183 184 185 186 187 188
            bool containsColors = false;
            for(size_t dimension = 0; dimension < m_minCoord.size(); dimension++ )
            {
                m_minCoord[dimension]->set( reader.getMinCoord()[dimension] );
                m_maxCoord[dimension]->set( reader.getMaxCoord()[dimension] );

                m_colorMin[dimension]->set( reader.getColorMin()[dimension] );
                m_colorMax[dimension]->set( reader.getColorMax()[dimension] );

                if( reader.getColorMax()[dimension] - reader.getColorMin()[dimension] > 0.0 )
                    containsColors = true;
            }
            if( !containsColors )
                m_colorsEnabled->set( false );
189 190
            m_intensityMin->set( reader.getIntensityMin() );
            m_intensityMax->set( reader.getIntensityMax() );
191

aschwarzkopf's avatar
aschwarzkopf committed
192 193 194 195 196 197
            m_output->updateData( tmpPointSet );
        } catch( ... )
        {
        }
        refreshScrollBars();

198 199 200
        m_reloadData->set( WPVBaseTypes::PV_TRIGGER_READY, true );
        m_reloadData->get( true );

Alexander Wiebel's avatar
Alexander Wiebel committed
201 202
        // woke up since the module is requested to finish?
        if( m_shutdownFlag() )
203 204 205 206 207 208 209
        {
            break;
        }
    }

    WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
210

aschwarzkopf's avatar
aschwarzkopf committed
211 212
void WMReadLAS::refreshScrollBars()
{
213 214 215 216
    m_sliderX->setMin( reader.getMinCoord()[0] );
    m_sliderX->setMax( reader.getMaxCoord()[0] );
    m_sliderY->setMin( reader.getMinCoord()[1] );
    m_sliderY->setMax( reader.getMaxCoord()[1] );
aschwarzkopf's avatar
aschwarzkopf committed
217

Alexander Wiebel's avatar
Alexander Wiebel committed
218 219
    m_sliderX->get( true );
    m_sliderY->get( true );
aschwarzkopf's avatar
aschwarzkopf committed
220
}