camera_control_pane.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id$
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by dcgm-robotics@FIT group.
00009  *
00010  * Author: Vit Stancl (stancl@fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: dd/mm/2011
00013  *
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #include <srs_ui_but/but_display/camera_control_pane.h>
00029 #include <rviz/window_manager_interface.h>
00030 #include <rviz/visualization_manager.h>
00031 
00032 #include <OgreCamera.h>
00033 
00034 #define MAX_RANGE 500
00035 
00036 // Controls
00037 const int ID_NEAR_PLANE_SPIN(201);
00038 const int ID_FAR_PLANE_SPIN(202);
00039 const int ID_NEAR_PLANE_TEXT(203);
00040 const int ID_FAR_PLANE_TEXT(204);
00041 const int ID_UPDATE_CLIPPING_LIMITS(205);
00042 const int ID_FAR_MAX_SPIN(206);
00043 
00047 srs_ui_but::CCameraControlPane::CCameraControlPane(wxWindow *parent, const wxString& title, rviz::WindowManagerInterface * wmi )
00048     : wxPanel( parent, wxID_ANY, wxDefaultPosition, wxSize(280, 180), wxCLOSE_BOX|wxTAB_TRAVERSAL | wxVSCROLL, title)
00049     , m_wmi( wmi )
00050         , m_camera( 0 )
00051 {
00052 
00053         /*
00054                  * +------------------------------------+
00055                  * | +Clipping planes-------------------+
00056                  * | | Near plane                                               |
00057                  * | | Far plane                                                |
00058                  * | | Far plane max spin                               |
00059                  * +------------------------------------+
00060         */
00061 
00062         // Create controls
00063         wxStaticText * stNearPlane = new wxStaticText(this, ID_NEAR_PLANE_TEXT, _T("Near plane"));
00064         m_sliderNearClipPlane = new wxSlider(this, ID_NEAR_PLANE_SPIN, 50, 0, 100, wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00065         wxStaticText * stFarPlane = new wxStaticText(this, ID_FAR_PLANE_TEXT, _T("Far plane"));
00066         m_sliderFarClipPlane = new wxSlider(this, ID_FAR_PLANE_SPIN, 50, 0, 100, wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00067         m_spinFarPlane = new wxSpinCtrl(this, ID_FAR_MAX_SPIN, _T("100"), wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00068 
00069         // Set sliders limits
00070         m_sliderNearClipPlane->SetRange( 0, MAX_RANGE );
00071         m_sliderNearClipPlane->SetValue( 0 );
00072 
00073         m_sliderFarClipPlane->SetRange(0, MAX_RANGE);
00074         m_sliderFarClipPlane->SetValue( 100 );
00075 
00076         m_spinFarPlane->SetRange(1, 10000);
00077         m_spinFarPlane->SetValue(100);
00078 
00079         // Create layout
00080         wxSizer *vsizer = new wxBoxSizer(wxVERTICAL);
00081         this->SetSizer(vsizer);
00082 
00083         // Clipping planes
00084         wxStaticBoxSizer *hsizerPlanesControls = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Clipping planes"));
00085         hsizerPlanesControls->Add( stNearPlane, ID_NEAR_PLANE_TEXT, wxALIGN_LEFT );
00086         hsizerPlanesControls->Add( m_sliderNearClipPlane, ID_NEAR_PLANE_SPIN, wxALIGN_LEFT );
00087         hsizerPlanesControls->Add( stFarPlane, ID_FAR_PLANE_TEXT, wxALIGN_LEFT );
00088         hsizerPlanesControls->Add( m_sliderFarClipPlane, ID_FAR_PLANE_SPIN, wxALIGN_LEFT );
00089         hsizerPlanesControls->Add( m_spinFarPlane, ID_FAR_MAX_SPIN, wxALIGN_LEFT);
00090 
00091         // Finalize
00092         vsizer->Add(hsizerPlanesControls, 0, wxALIGN_LEFT);
00093         vsizer->SetSizeHints(this);
00094 }
00095 
00099 void srs_ui_but::CCameraControlPane::setCamera( Ogre::Camera * camera )
00100 {
00101         m_camera = camera;
00102 
00103         if( camera == 0 )
00104         {
00105                 return;
00106         }
00107         m_nearDistanceMin = m_farDistanceMin = camera->getNearClipDistance();
00108 
00109         m_near = m_nearDistanceMin;
00110         m_far = camera->getFarClipDistance();
00111 
00112         updateClippingDistancesInfo();
00113 }
00114 
00118 void srs_ui_but::CCameraControlPane::OnNearPlane(wxScrollEvent& event)
00119 {
00120         if( m_camera != 0 && m_nearDistanceMax > 0.0 )
00121         {
00122                 m_near = m_nearDistanceMin + Ogre::Real( m_sliderNearClipPlane->GetValue()) / Ogre::Real(MAX_RANGE) * m_nearDistanceMax;
00123 //              std::cerr << "new near: " << m_near << std::endl;
00124                 m_camera->setNearClipDistance(m_near);
00125         }
00126 }
00127 
00131 void srs_ui_but::CCameraControlPane::OnFarPlane(wxScrollEvent& event)
00132 {
00133         if( m_camera != 0 && m_farDistanceMax > 0.0 )
00134         {
00135                 m_far = m_farDistanceMin + Ogre::Real( m_sliderFarClipPlane->GetValue()) / Ogre::Real(MAX_RANGE) * m_farDistanceMax;
00136 //              std::cerr << "new far: " << m_far << std::endl;
00137                 m_camera->setFarClipDistance(m_far);
00138         }
00139 }
00140 
00144 void srs_ui_but::CCameraControlPane::updateClippingDistancesInfo()
00145 {
00146         if( m_camera == 0 )
00147                 return;
00148 
00149         m_nearDistanceMax = m_farDistanceMax = m_spinFarPlane->GetValue();
00150         m_nearDistanceMin = m_farDistanceMin = 0.03;
00151 
00152 //      std::cerr << "Current: " << m_near << ", " << m_far << std::endl;
00153 //      std::cerr << "Near limits: " << m_nearDistanceMin << ", " << m_nearDistanceMax << std::endl;
00154 //      std::cerr << "Far limits: " << m_farDistanceMin << ", " << m_farDistanceMax << std::endl;
00155 
00156 
00157         // Set new limit to camera
00158         if( m_near > m_nearDistanceMax )
00159         {
00160                 m_camera->setNearClipDistance( m_nearDistanceMax );
00161                 m_near = m_nearDistanceMax;
00162                 m_camera->setNearClipDistance(m_near);
00163         }
00164 
00165         if( m_far > m_farDistanceMax )
00166         {
00167                 m_camera->setFarClipDistance( m_farDistanceMax );
00168                 m_far = m_farDistanceMax;
00169                 m_camera->setFarClipDistance(m_far);
00170         }
00171 
00172         // Update slider positions
00173         float n((Ogre::Real(MAX_RANGE) - 0.4 ) * m_near / m_nearDistanceMax);
00174         float f((Ogre::Real(MAX_RANGE) - 0.4 ) * m_far / m_farDistanceMax);
00175 
00176 //      std::cerr << "New slider values: " << n << ", " << f << std::endl;
00177 
00178         m_sliderNearClipPlane->SetValue( int( n ) );
00179         m_sliderFarClipPlane->SetValue( int( f ) );
00180 }
00181 
00185 void srs_ui_but::CCameraControlPane::OnMaxSpin(wxSpinEvent & event)
00186 {
00187         updateClippingDistancesInfo();
00188 }
00189 
00191 
00192 BEGIN_EVENT_TABLE(srs_ui_but::CCameraControlPane, wxPanel)
00193         EVT_COMMAND_SCROLL(ID_NEAR_PLANE_SPIN,  srs_ui_but::CCameraControlPane::OnNearPlane)
00194         EVT_COMMAND_SCROLL(ID_FAR_PLANE_SPIN,  srs_ui_but::CCameraControlPane::OnFarPlane)
00195     EVT_SPINCTRL(ID_FAR_MAX_SPIN, srs_ui_but::CCameraControlPane::OnMaxSpin)
00196 END_EVENT_TABLE()


srs_ui_but
Author(s): Vit Stancl (stancl@fit.vutbr.cz), Michal Spanel (spanel@fit.vutbr.cz), Tomas Lokaj
autogenerated on Mon Oct 6 2014 08:49:30