From: mpa Date: Mon, 26 Oct 2015 12:06:06 +0000 (+0300) Subject: 0023124: EDF 11219 GEOM: Ray tracing in the OCC viewer X-Git-Tag: V8_0_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=77a9b7ac9d8b364358e1760e74a44e86557b79aa;p=modules%2Fgui.git 0023124: EDF 11219 GEOM: Ray tracing in the OCC viewer --- diff --git a/doc/salome/gui/images/doc_dir_light_source.png b/doc/salome/gui/images/doc_dir_light_source.png new file mode 100644 index 000000000..b6e08ceaf Binary files /dev/null and b/doc/salome/gui/images/doc_dir_light_source.png differ diff --git a/doc/salome/gui/images/doc_env_texture.png b/doc/salome/gui/images/doc_env_texture.png new file mode 100644 index 000000000..133dc10a5 Binary files /dev/null and b/doc/salome/gui/images/doc_env_texture.png differ diff --git a/doc/salome/gui/images/doc_pos_light_source.png b/doc/salome/gui/images/doc_pos_light_source.png new file mode 100644 index 000000000..4732de773 Binary files /dev/null and b/doc/salome/gui/images/doc_pos_light_source.png differ diff --git a/doc/salome/gui/images/doc_ray_tracing.png b/doc/salome/gui/images/doc_ray_tracing.png new file mode 100644 index 000000000..496525794 Binary files /dev/null and b/doc/salome/gui/images/doc_ray_tracing.png differ diff --git a/doc/salome/gui/images/occviewer_toolbar.png b/doc/salome/gui/images/occviewer_toolbar.png index c8eefa245..d4b293757 100644 Binary files a/doc/salome/gui/images/occviewer_toolbar.png and b/doc/salome/gui/images/occviewer_toolbar.png differ diff --git a/doc/salome/gui/input/occ_3d_viewer.doc b/doc/salome/gui/input/occ_3d_viewer.doc index 09e821b48..7f79605ac 100644 --- a/doc/salome/gui/input/occ_3d_viewer.doc +++ b/doc/salome/gui/input/occ_3d_viewer.doc @@ -295,5 +295,76 @@ or other view operation done in one view is automatically applied to the other view.
+\image html occ_view_ray_tracing.png +\anchor ray_tracing + +Ray tracing - allows to switch between rendering methods in run-time +in the current OCCT 3D view. It can be used to produce images with photorealistic quality. + +\image html doc_ray_tracing.png + +- Ray tracing - specifies rendering mode: OpenGL rasterization (by default) or GPU ray-tracing. + + - Depth - defines maximum ray-tracing depth. + + - Specular reflections - enables/disables specular reflections. + + - Adaptive anti-aliasing - enables/disables adaptive anti-aliasing. + + - Shadows rendering - enables/disables shadows rendering. + + - Transparent shadow - enables/disables light propagation through transparent media. + +
+ +\image html occ_view_env_texture.png + +\anchor env_texture + +Environment texture - allows to set parameters for environment texture. +This is a special mode of texture mapping when specular reflection of environment texture +is simulated by OpenGL using a special texture coordinates generation algorithm (a sphere map). + +\image html doc_env_texture.png + +- Environment texture - enables/disables environment texture in the current OCCT 3D view. + +User can select one of 7 predefined environment texture from the list or define its texture from file by +choosing item "Custom..." in a combo box. + +\note Note that the environment texture file should normally satisfy the following requirements +in order to produce good visual result: +- The image file should have 2:1 width-to-height ratio. +- It should constitute a 360-degrees panoramic image created using a fish-eye lens. + +
+ +\image html occ_view_light_source.png + +\anchor light_source + +Light source - allows to set parameters for light source. + +It's possible to choose a type of light source between directional and positional light. + +\image html doc_dir_light_source.png + +Directional light - creates a directional light source in the viewer. +It is defined by direction coordinates, color and headlight parameter. + +\image html doc_pos_light_source.png + +Positional light - creates an isolated light source X,Y,Z in the viewer. +It is also defined by the color and headlight parameter. + +Click: + +- Apply and Close to apply defined light source to the OCC 3D Viewer. + +- Default to restore default values of light source. + +- Close to return parameters of light source on initial values. + +
*/ diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index f50576ea8..3093f12fc 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2515,6 +2515,61 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "step", 0.1, scaleFactor ); // ... "Clipping" group <> + // ... "Ray tracing" group <> + int occRayTracingGroup = pref->addPreference( tr( "PREF_GROUP_RAY_TRACING" ), occGroup ); + int rtPref = pref->addPreference( "", occRayTracingGroup, LightApp_Preferences::Frame ); + pref->setItemProperty( "columns", 2, rtPref ); + // .... -> depth + int rt_depth = pref->addPreference( tr( "PREF_RAY_TRACING_DEPTH" ), rtPref, + LightApp_Preferences::IntSpin, "OCCViewer", "rt_depth" ); + pref->setItemProperty( "min", 1, rt_depth ); + pref->setItemProperty( "max", 10, rt_depth ); + pref->setItemProperty( "step", 1, rt_depth ); + pref->addPreference( "", rtPref, LightApp_Preferences::Frame ); + // .... -> specular reflections + pref->addPreference( tr( "PREF_RAY_TRACING_REFLECTION" ), rtPref, + LightApp_Preferences::Bool, "OCCViewer", "rt_reflection" ); + // .... -> adaptive anti-aliasing + pref->addPreference( tr( "PREF_RAY_TRACING_ANTIALIASING" ), rtPref, + LightApp_Preferences::Bool, "OCCViewer", "rt_antialiasing" ); + // .... -> shadows rendering + pref->addPreference( tr( "PREF_RAY_TRACING_SHADOW" ), rtPref, + LightApp_Preferences::Bool, "OCCViewer", "rt_shadow" ); + // .... -> transparent shadow + pref->addPreference( tr( "PREF_RAY_TRACING_TRANS_SHADOW" ), rtPref, + LightApp_Preferences::Bool, "OCCViewer", "rt_trans_shadow" ); + // ... "Ray tracing" group <> + + // ... "Light source" group <> + int occLightGroup = pref->addPreference( tr( "PREF_GROUP_LIGHT" ), occGroup ); + // .... -> light color + pref->addPreference( tr( "PREF_LIGHT_COLOR" ), occLightGroup, + LightApp_Preferences::Color, "OCCViewer", "light_color" ); + int directionPref = pref->addPreference( "", occLightGroup, LightApp_Preferences::Frame ); + pref->setItemProperty( "columns", 3, directionPref ); + // .... -> light direction (dx component) + int light_dx = pref->addPreference( tr( "Dx" ), directionPref, + LightApp_Preferences::DblSpin, "OCCViewer", "light_dx" ); + pref->setItemProperty( "precision", 2, light_dx ); + pref->setItemProperty( "min", -1.0E03, light_dx ); + pref->setItemProperty( "max", 1.0E03, light_dx ); + pref->setItemProperty( "step", 0.1, light_dx ); + // .... -> light direction (dy component) + int light_dy = pref->addPreference( tr( "Dy" ), directionPref, + LightApp_Preferences::DblSpin, "OCCViewer", "light_dy" ); + pref->setItemProperty( "precision", 2, light_dy ); + pref->setItemProperty( "min", -1.0E03, light_dy ); + pref->setItemProperty( "max", 1.0E03, light_dy ); + pref->setItemProperty( "step", 0.1, light_dy ); + // .... -> light direction (dz component) + int light_dz = pref->addPreference( tr( "Dz" ), directionPref, + LightApp_Preferences::DblSpin, "OCCViewer", "light_dz" ); + pref->setItemProperty( "precision", 2, light_dz ); + pref->setItemProperty( "min", -1.0E03, light_dz ); + pref->setItemProperty( "max", 1.0E03, light_dz ); + pref->setItemProperty( "step", 0.1, light_dz ); + // ... "Light source" group <> + // ... -> empty frame (for layout) <> int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame ); pref->setItemProperty( "margin", 0, occGen ); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index e8a0858e1..befb3b4e2 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -160,6 +160,15 @@ + + + + + + + + + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 987657246..8fca4a604 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -851,6 +851,38 @@ The changes will be applied on the next application session. PREF_CLIPPING_SCALE Scale factor + + PREF_GROUP_RAY_TRACING + Ray tracing + + + PREF_RAY_TRACING_DEPTH + Depth + + + PREF_RAY_TRACING_REFLECTION + Specular reflections + + + PREF_RAY_TRACING_ANTIALIASING + Adaptive anti-aliasing + + + PREF_RAY_TRACING_SHADOW + Shadows rendering + + + PREF_RAY_TRACING_TRANS_SHADOW + Transparent shadow + + + PREF_GROUP_LIGHT + Light source + + + PREF_LIGHT_COLOR + Color + TOT_CLOSE Close diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 526ecd7d2..63b93ab94 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -851,6 +851,38 @@ Les modifications seront appliquées à la prochaine session. PREF_CLIPPING_SCALE Facteur d'échelle + + PREF_GROUP_RAY_TRACING + Ray tracing + + + PREF_RAY_TRACING_DEPTH + Depth + + + PREF_RAY_TRACING_REFLECTION + Specular reflections + + + PREF_RAY_TRACING_ANTIALIASING + Adaptive anti-aliasing + + + PREF_RAY_TRACING_SHADOW + Shadows rendering + + + PREF_RAY_TRACING_TRANS_SHADOW + Transparent shadow + + + PREF_GROUP_LIGHT + Light source + + + PREF_LIGHT_COLOR + Color + TOT_CLOSE Fermer diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index 29a70c646..084e385be 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -851,6 +851,38 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASPREF_CLIPPING_SCALE スケールファクタ + + PREF_GROUP_RAY_TRACING + Ray tracing + + + PREF_RAY_TRACING_DEPTH + Depth + + + PREF_RAY_TRACING_REFLECTION + Specular reflections + + + PREF_RAY_TRACING_ANTIALIASING + Adaptive anti-aliasing + + + PREF_RAY_TRACING_SHADOW + Shadows rendering + + + PREF_RAY_TRACING_TRANS_SHADOW + Transparent shadow + + + PREF_GROUP_LIGHT + Light source + + + PREF_LIGHT_COLOR + Color + TOT_CLOSE 閉じる diff --git a/src/OCCViewer/CMakeLists.txt b/src/OCCViewer/CMakeLists.txt index 01e7473bb..8c4159c85 100755 --- a/src/OCCViewer/CMakeLists.txt +++ b/src/OCCViewer/CMakeLists.txt @@ -36,6 +36,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/ViewerData ${PROJECT_SOURCE_DIR}/src/ViewerTools ${PROJECT_SOURCE_DIR}/src/OpenGLUtils + ${PROJECT_SOURCE_DIR}/src/CAF ) # additional preprocessor / compiler flags @@ -45,7 +46,7 @@ ADD_DEFINITIONS(${QT_DEFINITIONS} ${CAS_DEFINITIONS} ${OGL_DEFINITIONS}) SET(_link_LIBRARIES ${OPENGL_LIBRARIES} ${QT_LIBRARIES} ${CAS_KERNEL} ${CAS_VIEWER} ${CAS_TKGeomAlgo} ${CAS_TKTopAlgo} ${CAS_TKG2d} ${CAS_TKOpenGl} - CASCatch qtx suit ViewerTools ViewerData OpenGLUtils + CASCatch qtx suit ViewerTools ViewerData OpenGLUtils caf ) # --- headers --- @@ -55,6 +56,9 @@ SET(_moc_HEADERS OCCViewer_AISSelector.h OCCViewer_AxialScaleDlg.h OCCViewer_ClippingDlg.h + OCCViewer_RayTracingDlg.h + OCCViewer_EnvTextureDlg.h + OCCViewer_LightSourceDlg.h OCCViewer_CreateRestoreViewDlg.h OCCViewer_CubeAxesDlg.h OCCViewer_FontWidget.h @@ -141,6 +145,9 @@ SET(_other_RESOURCES resources/occ_view_triedre.png resources/occ_view_zoom.png resources/occ_view_zooming_style_switch.png + resources/occ_view_ray_tracing.png + resources/occ_view_env_texture.png + resources/occ_view_light_source.png ) # --- sources --- @@ -156,6 +163,9 @@ SET(_other_SOURCES OCCViewer_AISSelector.cxx OCCViewer_AxialScaleDlg.cxx OCCViewer_ClippingDlg.cxx + OCCViewer_RayTracingDlg.cxx + OCCViewer_EnvTextureDlg.cxx + OCCViewer_LightSourceDlg.cxx OCCViewer_ClipPlane.cxx OCCViewer_CreateRestoreViewDlg.cxx OCCViewer_CubeAxesDlg.cxx diff --git a/src/OCCViewer/OCCViewer_EnvTextureDlg.cxx b/src/OCCViewer/OCCViewer_EnvTextureDlg.cxx new file mode 100644 index 000000000..d1b0b35a8 --- /dev/null +++ b/src/OCCViewer/OCCViewer_EnvTextureDlg.cxx @@ -0,0 +1,237 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// internal includes +#include "OCCViewer_EnvTextureDlg.h" +#include "OCCViewer_ViewWindow.h" +#include "OCCViewer_ViewPort3d.h" +#include "OCCViewer_ViewFrame.h" + +// GUI includes +#include + +// OCCT includes +#include + +// QT Includes +#include +#include +#include +#include +#include +#include + +/*! + \class OCCViewer_EnvTextureDlg + \brief Dialog allowing to assign parameters of environment texture +*/ + +/*! + \brief Constructor + \param view - parent widget +*/ +OCCViewer_EnvTextureDlg::OCCViewer_EnvTextureDlg( OCCViewer_ViewWindow* view ) + :QDialog( view ) +{ + + // get current view frame (OCCViewer_ViewWindow->QFrame->OCCViewer_ViewFrame) + myViewFrame = dynamic_cast( view->parent()->parent() ); + myView3d = view->getViewPort()->getView(); + + setObjectName( "OCCViewer_EnvTextureDlg" ); + setWindowTitle( tr( "ENV_TEXTURE" ) ); + setModal( false ); + + setAttribute( Qt::WA_DeleteOnClose, true ); + + // Create layout for this dialog + QVBoxLayout* dlglayout = new QVBoxLayout( this ); + dlglayout->setSpacing( 6 ); + dlglayout->setMargin( 11 ); + + // Create "Environment texture" group + + myEnvTextureGroup = new QGroupBox( tr( "ENV_TEXTURE" ) ); + myEnvTextureGroup->setCheckable( true ); + + QGridLayout* envTextureLayout = new QGridLayout( myEnvTextureGroup ); + envTextureLayout->setSpacing( 6 ); + envTextureLayout->setMargin( 11 ); + + myEnvTextureId = new QComboBox(); + myEnvTextureId->addItem( tr( "ENV_CLOUDS" ) ); + myEnvTextureId->addItem( tr( "ENV_CV" ) ); + myEnvTextureId->addItem( tr( "ENV_MEDIT" ) ); + myEnvTextureId->addItem( tr( "ENV_PEARL" ) ); + myEnvTextureId->addItem( tr( "ENV_SKY1" ) ); + myEnvTextureId->addItem( tr( "ENV_SKY2" ) ); + myEnvTextureId->addItem( tr( "ENV_LINES" ) ); + myEnvTextureId->addItem( tr( "ENV_ROAD" ) ); + myEnvTextureId->addItem( tr( "ENV_CUSTOM" ) ); + myEnvTextureId->setMinimumWidth( 300 ); + + myEnvTextureName = new QLineEdit(); + myEnvTextureName->setVisible( false ); + myFileButton = new QPushButton(); + myFileButton->setText("..."); + myFileButton->setVisible( false ); + + envTextureLayout->addWidget( myEnvTextureId, 0, 0, 1, 2 ); + envTextureLayout->addWidget( myEnvTextureName, 1, 0 ); + envTextureLayout->addWidget( myFileButton, 1, 1 ); + + // Create "Buttons" group + + QGroupBox* groupButtons = new QGroupBox( this ); + QHBoxLayout* groupButtonsLayout = new QHBoxLayout( groupButtons ); + groupButtonsLayout->setSpacing( 6 ); + groupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonClose = new QPushButton( tr( "BUT_CLOSE" ) ); + buttonClose->setDefault( true ); + + QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) ); + + groupButtonsLayout->addStretch(); + groupButtonsLayout->addWidget( buttonClose ); + groupButtonsLayout->addWidget( buttonHelp ); + + dlglayout->addWidget( myEnvTextureGroup ); + dlglayout->addWidget( groupButtons ); + + // Initializations + initParam(); + + // Signals and slots connections + connect( myEnvTextureGroup, SIGNAL( toggled(bool) ), this, SLOT( onEnvTexture(bool) ) ); + connect( myEnvTextureId, SIGNAL( currentIndexChanged(int) ), this, SLOT( onTextureChanged() ) ); + connect( myFileButton, SIGNAL( clicked() ), this, SLOT( onFileSelectionClicked() ) ); + connect( buttonClose, SIGNAL( clicked() ), this, SLOT( close() ) ); + connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) ); +} + +/*! + \brief Destructor +*/ +OCCViewer_EnvTextureDlg::~OCCViewer_EnvTextureDlg() +{ +} + +QString OCCViewer_EnvTextureDlg::getName() +{ + // return the name of object + return QString( "OCCViewer_EnvTextureDlg" ); +} + +/*! + Initialization of initial values of widgets +*/ +void OCCViewer_EnvTextureDlg::initParam() +{ + Handle(Graphic3d_TextureEnv) aTexture = myView3d->TextureEnv(); + bool anIsTexture = !aTexture.IsNull(); + myEnvTextureGroup->setChecked( anIsTexture ); + if ( anIsTexture ) { + int aTextureId = myView3d->TextureEnv()->Name(); + myEnvTextureId->setCurrentIndex( aTextureId ); + if ( aTextureId == myEnvTextureId->count() - 1 ) { + TCollection_AsciiString aFileName; + aTexture->Path().SystemName( aFileName ); + myEnvTextureName->setText( QString( aFileName.ToCString() ) ); + myFileButton->setVisible( true ); + myEnvTextureName->setVisible( true ); + } + } +} + +/*! + SLOT on "Environment texture" group click +*/ +void OCCViewer_EnvTextureDlg::onEnvTexture( bool theIsChecked ) +{ + if ( theIsChecked ) + onTextureChanged(); + else { + Handle(Graphic3d_TextureEnv) aTexture; + setEnvTexture( aTexture, V3d_TEX_ALL ); + } +} + +/*! + SLOT on when user changed the texture +*/ +void OCCViewer_EnvTextureDlg::onTextureChanged() +{ + Handle(Graphic3d_TextureEnv) aTexture; + bool isCustom = myEnvTextureId->currentIndex() == myEnvTextureId->count()-1; + myEnvTextureName->setVisible( isCustom ); + myFileButton->setVisible( isCustom ); + if( isCustom ) { + if( myEnvTextureName->text().isEmpty() ) + onFileSelectionClicked(); + aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( myEnvTextureName->text().toStdString().c_str() ) ); + } + else { + myEnvTextureName->setText(""); + Graphic3d_NameOfTextureEnv aStandardTexture; + QList aTextures; + aTextures << Graphic3d_NOT_ENV_CLOUDS << Graphic3d_NOT_ENV_CV << Graphic3d_NOT_ENV_MEDIT + << Graphic3d_NOT_ENV_PEARL << Graphic3d_NOT_ENV_SKY1 << Graphic3d_NOT_ENV_SKY2 + << Graphic3d_NOT_ENV_LINES << Graphic3d_NOT_ENV_ROAD; + aTexture = new Graphic3d_TextureEnv( aTextures.at( myEnvTextureId->currentIndex() ) ); + } + setEnvTexture( aTexture, V3d_TEX_ENVIRONMENT ); +} + +/*! + SLOT on file selection button click +*/ +void OCCViewer_EnvTextureDlg::onFileSelectionClicked() +{ + QString selFile = QFileDialog::getOpenFileName( this,tr( "GEOM_SELECT_IMAGE" ),QString(), tr( "OCC_TEXTURE_FILES" ) ); + if ( !selFile.isEmpty() ) { + myEnvTextureName->setText( selFile ); + onTextureChanged(); + } +} + +/*! + SLOT on help button click: opens a help page +*/ +void OCCViewer_EnvTextureDlg::ClickOnHelp() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) + app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "env_texture" ); +} + +/*! + Sets current texture environment for all view in the viewer +*/ +void OCCViewer_EnvTextureDlg::setEnvTexture( Handle(Graphic3d_TextureEnv) theTexture, V3d_TypeOfSurfaceDetail theMode ) +{ + for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) { + if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) { + Handle(V3d_View) aView = aViewWindow->getViewPort()->getView(); + aView->SetTextureEnv( theTexture ); + aView->SetSurfaceDetail( theMode ); + aView->Redraw(); + } + } +} diff --git a/src/OCCViewer/OCCViewer_EnvTextureDlg.h b/src/OCCViewer/OCCViewer_EnvTextureDlg.h new file mode 100644 index 000000000..0d172ff7f --- /dev/null +++ b/src/OCCViewer/OCCViewer_EnvTextureDlg.h @@ -0,0 +1,64 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef OCCVIEWER_ENVTEXTUREDLG_H +#define OCCVIEWER_ENVTEXTUREDLG_H + +#include "OCCViewer.h" +#include +#include + +class OCCViewer_ViewWindow; +class OCCViewer_ViewFrame; +class QGroupBox; +class QComboBox; +class QLineEdit; + +class OCCVIEWER_EXPORT OCCViewer_EnvTextureDlg : public QDialog +{ + Q_OBJECT + + public: + OCCViewer_EnvTextureDlg( OCCViewer_ViewWindow* ); + ~OCCViewer_EnvTextureDlg(); + + static QString getName(); + +private slots: + + void onEnvTexture( bool ); + void onTextureChanged(); + void onFileSelectionClicked(); + + void ClickOnHelp(); + +private: + void initParam(); + void setEnvTexture( Handle(Graphic3d_TextureEnv), V3d_TypeOfSurfaceDetail ); + + OCCViewer_ViewFrame* myViewFrame; + Handle(V3d_View) myView3d; + + QGroupBox* myEnvTextureGroup; + QComboBox* myEnvTextureId; + QLineEdit* myEnvTextureName; + QPushButton* myFileButton; +}; + +#endif // OCCVIEWER_ENVTEXTUREDLG_H diff --git a/src/OCCViewer/OCCViewer_LightSourceDlg.cxx b/src/OCCViewer/OCCViewer_LightSourceDlg.cxx new file mode 100644 index 000000000..ead1b69ce --- /dev/null +++ b/src/OCCViewer/OCCViewer_LightSourceDlg.cxx @@ -0,0 +1,431 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// internal includes +#include "OCCViewer_LightSourceDlg.h" +#include "OCCViewer_ViewWindow.h" +#include "OCCViewer_ViewModel.h" + +// GUI includes +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + \class OCCViewer_LightSourceDlg + \brief Dialog allowing to assign parameters of light source +*/ + +/*! + \brief Constructor + \param view - parent widget + \param model - viewer +*/ +OCCViewer_LightSourceDlg::OCCViewer_LightSourceDlg( OCCViewer_ViewWindow* view, OCCViewer_Viewer* model ) + :QDialog( view ), + myModel( model ) +{ + setObjectName( "OCCViewer_LightSourceDlg" ); + setWindowTitle( tr( "LIGHT_SOURCE" ) ); + setModal( false ); + + setAttribute( Qt::WA_DeleteOnClose, true ); + + // Create layout for this dialog + QVBoxLayout* dlglayout = new QVBoxLayout( this ); + dlglayout->setSpacing( 6 ); dlglayout->setMargin( 11 ); + + QGroupBox* typeGroup = new QGroupBox( tr( "TYPE" ), this ); + QHBoxLayout* typeLayout = new QHBoxLayout( typeGroup ); + typeLayout->setSpacing( 6 ); typeLayout->setMargin( 11 ); + + myDirType = new QRadioButton( tr( "DIRECTIONAL" ), typeGroup ); + myPosType = new QRadioButton( tr( "POSITIONAL" ), typeGroup ); + + typeLayout->addWidget( myDirType ); + typeLayout->addWidget( myPosType ); + + myStackedLayout = new QStackedLayout(); + + const double min = -RealLast(); + const double max = RealLast(); + const int precision = 3; + + /********************** Directional light **********************/ + /* Controls for directional light: + Dx, Dy, Dz - direction + Headlight - headlight flag + Color - the color of a light source + */ + + QWidget* dirWidget = new QWidget( this ); + QVBoxLayout* dirLayout = new QVBoxLayout( dirWidget ); + dirLayout->setSpacing( 6 ); dirLayout->setMargin( 11 ); + + // Create "Direction" group + + const double dir_step = 0.1; + + QGroupBox* dirCoordGroup = new QGroupBox( tr( "DIRECTION" ), this ); + QHBoxLayout* dirCoordLayout = new QHBoxLayout( dirCoordGroup ); + dirCoordLayout->setSpacing( 6 ); dirCoordLayout->setMargin( 11 ); + + QLabel* dxLabel = new QLabel( tr("Dx:"), dirCoordGroup ); + myDx = new QtxDoubleSpinBox( min, max, dir_step, dirCoordGroup ); + myDx->setValue( 0.0 ); + myDx->setMinimumWidth( 80 ); + + QLabel* dyLabel = new QLabel( tr("Dy:"), dirCoordGroup ); + myDy = new QtxDoubleSpinBox( min, max, dir_step, dirCoordGroup ); + myDy->setValue( 0.0 ); + myDy->setMinimumWidth( 80 ); + + QLabel* dzLabel = new QLabel( tr("Dz:"), dirCoordGroup ); + myDz = new QtxDoubleSpinBox( min, max, dir_step, dirCoordGroup ); + myDz->setValue( -1.0 ); + myDz->setMinimumWidth( 80 ); + + dirCoordLayout->addWidget( dxLabel ); + dirCoordLayout->addWidget( myDx ); + dirCoordLayout->addWidget( dyLabel ); + dirCoordLayout->addWidget( myDy ); + dirCoordLayout->addWidget( dzLabel ); + dirCoordLayout->addWidget( myDz ); + + // Create "Parameters" group + + QGroupBox* dirParamGroup = new QGroupBox( dirWidget ); + QHBoxLayout* dirParamLayout = new QHBoxLayout( dirParamGroup ); + dirParamLayout->setSpacing( 6 ); dirParamLayout->setMargin( 11 ); + + myDirHeadLight = new QCheckBox( tr("HEADLIGHT"), dirParamGroup ); + myDirHeadLight->setChecked( false ); + + QLabel* aColorLabel = new QLabel( tr( "COLOR" ), dirParamGroup ); + myDirColor = new QtxColorButton( dirParamGroup ); + myDirColor->setColor( Qt::white ); + + dirParamLayout->addWidget( myDirHeadLight ); + dirParamLayout->addWidget( aColorLabel ); + dirParamLayout->addWidget( myDirColor ); + dirParamLayout->addStretch(); + + dirLayout->addWidget( dirCoordGroup ); + dirLayout->addWidget( dirParamGroup ); + + /********************** Positional light **********************/ + /* Controls for positional light: + X, Y, Z - position + Headlight - headlight flag + Color - the color of a light source + */ + + QWidget* posWidget = new QWidget( this ); + QVBoxLayout* posLayout = new QVBoxLayout( posWidget ); + posLayout->setSpacing( 6 ); posLayout->setMargin( 11 ); + + // Create "Position" group + + const double pos_step = 1.0; + + QGroupBox* posCoordGroup = new QGroupBox( tr( "POSITION" ), posWidget ); + QHBoxLayout* posCoordLayout = new QHBoxLayout( posCoordGroup ); + posCoordLayout->setSpacing( 6 ); posCoordLayout->setMargin( 11 ); + + QLabel* xLabel = new QLabel( tr("X:"), posCoordGroup ); + myX = new QtxDoubleSpinBox( min, max, pos_step, posCoordGroup ); + myX->setValue( 0.0 ); + myX->setMinimumWidth( 80 ); + + QLabel* yLabel = new QLabel( tr("Y:"), posCoordGroup ); + myY = new QtxDoubleSpinBox( min, max, pos_step, posCoordGroup ); + myY->setValue( 0.0 ); + myY->setMinimumWidth( 80 ); + + QLabel* zLabel = new QLabel( tr("Z:"), posCoordGroup ); + myZ = new QtxDoubleSpinBox( min, max, pos_step, posCoordGroup ); + myZ->setValue( 0.0 ); + myZ->setMinimumWidth( 80 ); + + posCoordLayout->addWidget( xLabel ); + posCoordLayout->addWidget( myX ); + posCoordLayout->addWidget( yLabel ); + posCoordLayout->addWidget( myY ); + posCoordLayout->addWidget( zLabel ); + posCoordLayout->addWidget( myZ ); + + // Create "Parameters" group + + QGroupBox* posParamGroup = new QGroupBox( posWidget ); + QHBoxLayout* posParamLayout = new QHBoxLayout( posParamGroup ); + posParamLayout->setSpacing( 6 ); posParamLayout->setMargin( 11 ); + + myPosHeadLight = new QCheckBox( tr("HEADLIGHT"), posParamGroup ); + myPosHeadLight->setChecked( false ); + + aColorLabel = new QLabel( tr( "COLOR" ), posParamGroup ); + myPosColor = new QtxColorButton( posParamGroup ); + myPosColor->setColor( Qt::white ); + + posParamLayout->addWidget( myPosHeadLight ); + posParamLayout->addWidget( aColorLabel ); + posParamLayout->addWidget( myPosColor ); + posParamLayout->addStretch(); + + posLayout->addWidget( posCoordGroup ); + posLayout->addWidget( posParamGroup ); + + // add widgets in the stacked layout + myStackedLayout->addWidget( dirWidget ); + myStackedLayout->addWidget( posWidget ); + + // Create "Buttons" group + + QGroupBox* buttonGroup = new QGroupBox( this ); + QHBoxLayout* buttonLayout = new QHBoxLayout( buttonGroup ); + buttonLayout->setSpacing( 6 ); + buttonLayout->setMargin( 11 ); + + QPushButton* okButton = new QPushButton( tr( "BUT_APPLY_AND_CLOSE" ), buttonGroup ); + okButton->setDefault( true ); + QPushButton* defaultButton = new QPushButton( tr( "BUT_DEFAULT" ), buttonGroup ); + QPushButton* closeButton = new QPushButton( tr( "BUT_CLOSE" ), buttonGroup ); + QPushButton* helpButton = new QPushButton( tr( "GEOM_BUT_HELP" ), buttonGroup ); + + buttonLayout->addWidget( okButton ); + buttonLayout->addWidget( defaultButton ); + buttonLayout->addStretch(); + buttonLayout->addWidget( closeButton ); + buttonLayout->addWidget( helpButton ); + + dlglayout->addWidget( typeGroup ); + dlglayout->addLayout( myStackedLayout ); + dlglayout->addWidget( buttonGroup ); + + this->setLayout( dlglayout ); + + // Initializations + initParam(); + isBusy = false; + + // Signals and slots connections + connect( myDirType, SIGNAL( clicked( bool ) ), this, SLOT( onTypeChanged() ) ); + connect( myPosType, SIGNAL( clicked( bool ) ), this, SLOT( onTypeChanged() ) ); + + connect( myDx, SIGNAL( valueChanged( double ) ), this, SLOT( onDirChanged() ) ); + connect( myDy, SIGNAL( valueChanged( double ) ), this, SLOT( onDirChanged() ) ); + connect( myDz, SIGNAL( valueChanged( double ) ), this, SLOT( onDirChanged() ) ); + connect( myDirHeadLight, SIGNAL( clicked( bool ) ), this, SLOT( onDirChanged() ) ); + connect( myDirColor, SIGNAL( changed( QColor ) ), this, SLOT( onDirChanged() ) ); + + connect( myX, SIGNAL( valueChanged( double ) ), this, SLOT( onPosChanged() ) ); + connect( myY, SIGNAL( valueChanged( double ) ), this, SLOT( onPosChanged() ) ); + connect( myZ, SIGNAL( valueChanged( double ) ), this, SLOT( onPosChanged() ) ); + connect( myPosHeadLight, SIGNAL( clicked( bool ) ), this, SLOT( onPosChanged() ) ); + connect( myPosColor, SIGNAL( changed( QColor ) ), this, SLOT( onPosChanged() ) ); + + connect( okButton, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( defaultButton, SIGNAL( clicked() ), this, SLOT( ClickOnDefault() ) ); + connect( closeButton, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) ); + connect( helpButton, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) ); + + resize( minimumSizeHint() ); +} + +/*! + \brief Destructor +*/ +OCCViewer_LightSourceDlg::~OCCViewer_LightSourceDlg() +{ + ( myInType == V3d_DIRECTIONAL ) ? myModel->getViewer3d()->DelLight( myPosLight ) : + myModel->getViewer3d()->DelLight( myDirLight ); +} + +QString OCCViewer_LightSourceDlg::getName() +{ + // return the name of object + return QString( "OCCViewer_LightSourceDlg" ); +} + +/*! + Initialization of initial values of widgets +*/ +void OCCViewer_LightSourceDlg::initParam( bool theIsDefault ) +{ + Handle(V3d_Light) aLight; + myModel->getViewer3d()->InitDefinedLights(); + while ( myModel->getViewer3d()->MoreDefinedLights() ) + { + aLight = myModel->getViewer3d()->DefinedLight(); + if ( aLight->Type() == V3d_DIRECTIONAL ) { + myDirLight = Handle(V3d_DirectionalLight)::DownCast( aLight ); + myPosLight = new V3d_PositionalLight( myModel->getViewer3d(), 0, 0, 0 ); + myDirType->setChecked( true ); + myStackedLayout->setCurrentIndex(0); + break; + } + if ( aLight->Type() == V3d_POSITIONAL ) { + myPosLight = Handle(V3d_PositionalLight)::DownCast( aLight ); + myDirLight = new V3d_DirectionalLight( myModel->getViewer3d() ); + myPosType->setChecked( true ); + myStackedLayout->setCurrentIndex(1); + break; + } + myModel->getViewer3d()->NextDefinedLights(); + } + + double aX, aY, aZ; + Quantity_Color aColor = aLight->Color(); + if( myDirType->isChecked() ) { + myDirColor->setColor( CAF_Tools::color( aColor ) ); + myDirLight->Direction( aX, aY, aZ ); + myDx->setValue( aX ); + myDy->setValue( aY ); + myDz->setValue( aZ ); + myDirHeadLight->setChecked( myDirLight->Headlight() ); + } + else if( myPosType->isChecked() ) { + myPosColor->setColor( CAF_Tools::color( aColor ) ); + myPosLight->Position( aX, aY, aZ ); + myX->setValue( aX ); + myY->setValue( aY ); + myZ->setValue( aZ ); + myPosHeadLight->setChecked( myPosLight->Headlight() ); + } + + if ( !theIsDefault ) { + myInX = aX; myInY = aY; myInZ = aZ; + myInColor = aColor; + myInHeadLight = aLight->Headlight(); + myInType = aLight->Type(); + } +} + +/*! + SLOT: called on type of light source changed +*/ +void OCCViewer_LightSourceDlg::onTypeChanged() +{ + if( isBusy ) + return; + myStackedLayout->setCurrentIndex( myPosType->isChecked() ); + if( myPosType->isChecked() ) { + myModel->getViewer3d()->SetLightOff( myDirLight ); + onPosChanged(); + } + else if( myDirType->isChecked() ) { + myModel->getViewer3d()->SetLightOff( myPosLight ); + onDirChanged(); + } +} + +/*! + SLOT: called on value of directional light source changed +*/ +void OCCViewer_LightSourceDlg::onDirChanged() +{ + if( isBusy ) + return; + myModel->getViewer3d()->SetLightOff( myDirLight ); + if ( !( myDx->value() == 0 && myDy->value() == 0 && myDz->value() == 0 ) ) { + myDirLight->SetDirection( myDx->value(), myDy->value(), myDz->value() ); + myDirLight->SetColor( CAF_Tools::color( myDirColor->color() ) ); + myDirLight->SetHeadlight( myDirHeadLight->isChecked() ); + myModel->getViewer3d()->SetLightOn( myDirLight ); + } + myModel->getViewer3d()->UpdateLights(); +} + +/*! + SLOT: called on value of positional light source changed +*/ +void OCCViewer_LightSourceDlg::onPosChanged() +{ + if( isBusy ) + return; + myModel->getViewer3d()->SetLightOff( myPosLight ); + myPosLight->SetPosition( myX->value(), myY->value(), myZ->value() ); + myPosLight->SetColor( CAF_Tools::color( myPosColor->color() ) ); + myPosLight->SetHeadlight( myPosHeadLight->isChecked() ); + myModel->getViewer3d()->SetLightOn( myPosLight ); + myModel->getViewer3d()->UpdateLights(); +} + +/*! + \brief SLOT on "Apply and Close" button click: sets current light source and closes dialog +*/ +void OCCViewer_LightSourceDlg::ClickOnOk() +{ + // need save a current type for deleting other light when dialog will be closed + myInType = myDirType->isChecked() ? V3d_DIRECTIONAL : V3d_POSITIONAL; + close(); +} + +/*! + \brief SLOT on "Default" button click: sets default light source +*/ +void OCCViewer_LightSourceDlg::ClickOnDefault() +{ + isBusy = true; + myModel->setDefaultLights(); + initParam( true ); + myModel->getViewer3d()->UpdateLights(); + isBusy = false; +} + +/*! + \brief SLOT on "Close" button click: sets initial light source and closes dialog +*/ +void OCCViewer_LightSourceDlg::ClickOnClose() +{ + if( myInType == V3d_DIRECTIONAL ) { + myDirLight->SetDirection( myInX, myInY, myInZ ); + myDirLight->SetColor( myInColor ); + myDirLight->SetHeadlight( myInHeadLight ); + myModel->getViewer3d()->SetLightOn( myDirLight ); + } + else { + myPosLight->SetPosition( myInX, myInY, myInZ ); + myPosLight->SetColor( myInColor ); + myPosLight->SetHeadlight( myInHeadLight ); + myModel->getViewer3d()->SetLightOn( myPosLight ); + } + close(); +} + +/*! + \brief SLOT on help button click: opens a help page +*/ +void OCCViewer_LightSourceDlg::ClickOnHelp() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) + app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "light_source" ); +} diff --git a/src/OCCViewer/OCCViewer_LightSourceDlg.h b/src/OCCViewer/OCCViewer_LightSourceDlg.h new file mode 100644 index 000000000..7cf62ff81 --- /dev/null +++ b/src/OCCViewer/OCCViewer_LightSourceDlg.h @@ -0,0 +1,93 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef OCCVIEWER_LIGHTSOURCEDLG_H +#define OCCVIEWER_LIGHTSOURCEDLG_H + +#include "OCCViewer.h" +#include +#include +#include +#include + +class OCCViewer_ViewWindow; +class OCCViewer_Viewer; +class QtxDoubleSpinBox; +class QtxColorButton; +class QPushButton; +class QCheckBox; +class QRadioButton; +class QStackedLayout; + +class OCCVIEWER_EXPORT OCCViewer_LightSourceDlg: public QDialog +{ + Q_OBJECT + +public: + OCCViewer_LightSourceDlg( OCCViewer_ViewWindow*, OCCViewer_Viewer* ); + ~OCCViewer_LightSourceDlg(); + + static QString getName(); + +protected slots: + +private slots: + void onTypeChanged(); + void onDirChanged(); + void onPosChanged(); + + void ClickOnOk(); + void ClickOnDefault(); + void ClickOnClose(); + void ClickOnHelp(); + +private: + void initParam( bool theIsDefault = false ); + + OCCViewer_Viewer* myModel; + + Handle(V3d_DirectionalLight) myDirLight; + Handle(V3d_PositionalLight) myPosLight; + + QRadioButton* myDirType; + QRadioButton* myPosType; + + QStackedLayout* myStackedLayout; + + QtxDoubleSpinBox* myDx; + QtxDoubleSpinBox* myDy; + QtxDoubleSpinBox* myDz; + QCheckBox* myDirHeadLight; + QtxColorButton* myDirColor; + + QtxDoubleSpinBox* myX; + QtxDoubleSpinBox* myY; + QtxDoubleSpinBox* myZ; + QCheckBox* myPosHeadLight; + QtxColorButton* myPosColor; + + double myInX, myInY, myInZ; + bool myInHeadLight; + Quantity_Color myInColor; + V3d_TypeOfLight myInType; + + bool isBusy; +}; + +#endif // OCCVIEWER_LIGHTSOURCEDLG_H diff --git a/src/OCCViewer/OCCViewer_RayTracingDlg.cxx b/src/OCCViewer/OCCViewer_RayTracingDlg.cxx new file mode 100644 index 000000000..11a6d017a --- /dev/null +++ b/src/OCCViewer/OCCViewer_RayTracingDlg.cxx @@ -0,0 +1,188 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// internal includes +#include "OCCViewer_RayTracingDlg.h" +#include "OCCViewer_ViewWindow.h" +#include "OCCViewer_ViewPort3d.h" +#include "OCCViewer_ViewFrame.h" + +// GUI includes +#include +#include + +// QT Includes +#include +#include +#include +#include +#include + +/*! + \class OCCViewer_RayTracingDlg + \brief Dialog allowing to assign parameters of ray tracing +*/ + +/*! + \brief Constructor + \param view - parent widget +*/ +OCCViewer_RayTracingDlg::OCCViewer_RayTracingDlg( OCCViewer_ViewWindow* view ) + :QDialog( view ) +{ + // get current view frame (OCCViewer_ViewWindow->QFrame->OCCViewer_ViewFrame) + myViewFrame = dynamic_cast( view->parent()->parent() ); + myView3d = view->getViewPort()->getView(); + setObjectName( "OCCViewer_RayTracingDlg" ); + setWindowTitle( tr( "RAY_TRACING" ) ); + setModal( false ); + + setAttribute( Qt::WA_DeleteOnClose, true ); + + // Create layout for this dialog + QVBoxLayout* dlglayout = new QVBoxLayout( this ); + dlglayout->setSpacing( 6 ); + dlglayout->setMargin( 11 ); + + // Create "Ray tracing" group + + myRayTracingGroup = new QGroupBox( tr( "RAY_TRACING" ) ); + myRayTracingGroup->setCheckable( true ); + + QGridLayout* rayTracingLayout = new QGridLayout( myRayTracingGroup ); + rayTracingLayout->setSpacing( 6 ); + rayTracingLayout->setMargin( 11 ); + + myShadow = new QCheckBox( tr("SHADOW") ); + myReflection = new QCheckBox( tr("REFLECTION") ); + myAntialiasing = new QCheckBox( tr("ANTIALIASING") ); + myTransparentShadow = new QCheckBox( tr("TRANSPARENT_SHADOW") ); + QLabel* depthLabel = new QLabel( tr( "DEPTH" ) ); + myDepth = new QtxIntSpinBox( 1, 10 ); + + rayTracingLayout->addWidget( depthLabel, 0, 0 ); + rayTracingLayout->addWidget( myDepth, 0, 1 ); + rayTracingLayout->addWidget( myReflection, 1, 0 ); + rayTracingLayout->addWidget( myAntialiasing, 1, 1 ); + rayTracingLayout->addWidget( myShadow, 2, 0 ); + rayTracingLayout->addWidget( myTransparentShadow, 2, 1 ); + + // Create "Buttons" group + + QGroupBox* groupButtons = new QGroupBox( this ); + QHBoxLayout* groupButtonsLayout = new QHBoxLayout( groupButtons ); + groupButtonsLayout->setSpacing( 6 ); + groupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonClose = new QPushButton( tr( "BUT_CLOSE" ) ); + buttonClose->setDefault( true ); + + QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) ); + + groupButtonsLayout->addStretch(); + groupButtonsLayout->addWidget( buttonClose ); + groupButtonsLayout->addWidget( buttonHelp ); + + dlglayout->addWidget( myRayTracingGroup ); + dlglayout->addWidget( groupButtons ); + + // Initializations + initParam(); + + // Signals and slots connections + connect( myRayTracingGroup, SIGNAL( toggled(bool) ), this, SLOT( onRayTracing(bool) ) ); + connect( myShadow, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) ); + connect( myReflection, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) ); + connect( myAntialiasing, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) ); + connect( myTransparentShadow, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) ); + connect( myDepth, SIGNAL( valueChanged(int) ), this, SLOT( onValueChanged() ) ); + connect( buttonClose, SIGNAL( clicked() ), this, SLOT( close() ) ) ; + connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) ); +} + +/*! + \brief Destructor +*/ +OCCViewer_RayTracingDlg::~OCCViewer_RayTracingDlg() +{ +} + +QString OCCViewer_RayTracingDlg::getName() +{ + // return the name of object + return QString( "OCCViewer_RayTracingDlg" ); +} + +/*! + Initialization of initial values of widgets +*/ +void OCCViewer_RayTracingDlg::initParam() +{ + Graphic3d_RenderingParams aParams = myView3d->RenderingParams(); + myRayTracingGroup->setChecked( aParams.Method == Graphic3d_RM_RAYTRACING ); + myDepth->setValue( aParams.RaytracingDepth ); + myReflection->setChecked( aParams.IsReflectionEnabled ); + myAntialiasing->setChecked( aParams.IsAntialiasingEnabled ); + myShadow->setChecked( aParams.IsShadowEnabled ); + myTransparentShadow->setChecked( aParams.IsTransparentShadowEnabled ); +} + +/*! + SLOT: called on value of ray tracing changed +*/ +void OCCViewer_RayTracingDlg::onValueChanged() +{ + for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) { + if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) { + Handle(V3d_View) aView = aViewWindow->getViewPort()->getView(); + Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); + aParams.IsShadowEnabled = myShadow->isChecked(); + aParams.IsReflectionEnabled = myReflection->isChecked(); + aParams.IsAntialiasingEnabled = myAntialiasing->isChecked(); + aParams.IsTransparentShadowEnabled = myTransparentShadow->isChecked(); + aParams.RaytracingDepth = myDepth->value(); + aView->Redraw(); + } + } +} + +/*! + SLOT on "Ray tracing" group click +*/ +void OCCViewer_RayTracingDlg::onRayTracing( bool theIsChecked ) +{ + for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) { + if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) { + Handle(V3d_View) aView = aViewWindow->getViewPort()->getView(); + Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); + theIsChecked ? aParams.Method = Graphic3d_RM_RAYTRACING : aParams.Method = Graphic3d_RM_RASTERIZATION; + aView->Redraw(); + } + } +} + +/*! + SLOT on help button click: opens a help page +*/ +void OCCViewer_RayTracingDlg::ClickOnHelp() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) + app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "ray_tracing" ); +} diff --git a/src/OCCViewer/OCCViewer_RayTracingDlg.h b/src/OCCViewer/OCCViewer_RayTracingDlg.h new file mode 100644 index 000000000..9a7ba4903 --- /dev/null +++ b/src/OCCViewer/OCCViewer_RayTracingDlg.h @@ -0,0 +1,65 @@ +// Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library 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 2.1 of the License, or (at your option) any later version. +// +// This library 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 this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef OCCVIEWER_RAYTRACINGDLG_H +#define OCCVIEWER_RAYTRACINGDLG_H + +#include "OCCViewer.h" +#include +#include + +class OCCViewer_ViewWindow; +class OCCViewer_ViewFrame; +class QCheckBox; +class QtxIntSpinBox; +class QGroupBox; + + +class OCCVIEWER_EXPORT OCCViewer_RayTracingDlg : public QDialog +{ + Q_OBJECT + + public: + OCCViewer_RayTracingDlg( OCCViewer_ViewWindow* ); + ~OCCViewer_RayTracingDlg(); + + static QString getName(); + +private slots: + + void onValueChanged(); + void onRayTracing(bool); + + void ClickOnHelp(); + +private: + void initParam(); + + OCCViewer_ViewFrame* myViewFrame; + Handle(V3d_View) myView3d; + + QGroupBox* myRayTracingGroup; + QtxIntSpinBox* myDepth; + QCheckBox* myReflection; + QCheckBox* myAntialiasing; + QCheckBox* myShadow; + QCheckBox* myTransparentShadow; +}; + +#endif // OCCVIEWER_RAYTRACINGDLG_H diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx index 2818884c3..18e9096bc 100755 --- a/src/OCCViewer/OCCViewer_Utilities.cxx +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@ -36,6 +36,7 @@ // QT includes #include #include +#include Handle(Image_PixMap) OCCViewer_Utilities::imageToPixmap( const QImage& anImage ) { @@ -135,3 +136,14 @@ OCCViewer_ViewWindow::Mode2dType OCCViewer_Utilities::setViewer2DMode return anOldMode; } + +bool OCCViewer_Utilities::isDialogOpened( OCCViewer_ViewWindow* theView, const QString& theName ) +{ + bool isFound = false; + OCCViewer_ViewFrame* aViewFrame = dynamic_cast( theView->parent()->parent() ); + QList allDialogs = qFindChildren( aViewFrame ); + foreach ( QDialog* d, allDialogs ) + if ( d->objectName() == theName ) + isFound = true; + return isFound; +} diff --git a/src/OCCViewer/OCCViewer_Utilities.h b/src/OCCViewer/OCCViewer_Utilities.h index 125c0c458..484494543 100755 --- a/src/OCCViewer/OCCViewer_Utilities.h +++ b/src/OCCViewer/OCCViewer_Utilities.h @@ -55,6 +55,14 @@ public: setViewer2DMode( OCCViewer_Viewer* theViewer, const OCCViewer_ViewWindow::Mode2dType& theMode ); + /*! + * Find dialog in the current view frame by name + * \param theView an OCC view + * \param theName name of dialog + * \return true/false if dialog is opened/isn't opened + */ + static bool isDialogOpened( OCCViewer_ViewWindow* theView, const QString& theName ); + }; #endif // OCCVIEWER_UTILITIES_H diff --git a/src/OCCViewer/OCCViewer_ViewFrame.cxx b/src/OCCViewer/OCCViewer_ViewFrame.cxx index e4c3ec904..e3313a8b0 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.cxx +++ b/src/OCCViewer/OCCViewer_ViewFrame.cxx @@ -23,6 +23,7 @@ #include "OCCViewer_ViewFrame.h" #include "OCCViewer_ViewWindow.h" #include "OCCViewer_ViewModel.h" +#include "OCCViewer_ViewPort3d.h" #include #include @@ -169,10 +170,25 @@ void OCCViewer_ViewFrame::createSubViews() view->setDropDownButtons( dropDownButtons() ); connectViewSignals(view); view->setBackground(aModel->background(i)); + setSubViewParams( view ); } } } +//************************************************************************************** +void OCCViewer_ViewFrame::setSubViewParams( OCCViewer_ViewWindow* theView ) +{ + Handle(V3d_View) aView = theView->getViewPort()->getView(); + Handle(V3d_View) aMainView = myViews.at( MAIN_VIEW )->getViewPort()->getView(); + + // set ray tracing parameters + aView->ChangeRenderingParams() = aMainView->RenderingParams(); + + // set environment texture parameters + aView->SetTextureEnv( aMainView->TextureEnv() ); + aView->SetSurfaceDetail( aMainView->SurfaceDetail() ); +} + void OCCViewer_ViewFrame::splitSubViews() { if( mySplitMode == -1 ) diff --git a/src/OCCViewer/OCCViewer_ViewFrame.h b/src/OCCViewer/OCCViewer_ViewFrame.h index e7bb37726..ec4cfc773 100644 --- a/src/OCCViewer/OCCViewer_ViewFrame.h +++ b/src/OCCViewer/OCCViewer_ViewFrame.h @@ -172,6 +172,7 @@ private: void updateWindowTitle( OCCViewer_ViewWindow* theView ); void createSubViews(); void splitSubViews(); + void setSubViewParams( OCCViewer_ViewWindow* theView ); QList myViews; QGridLayout* myLayout; diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 282cc5721..fe2546853 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -36,6 +36,8 @@ #include "ViewerData_AISShape.hxx" +#include "CAF_Tools.h" + #include #include "QtxActionToolMgr.h" @@ -73,6 +75,9 @@ #include +#include +#include + /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ @@ -120,7 +125,7 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) // init CasCade viewers myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() ); //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267) - myV3dViewer->SetDefaultLights(); + setDefaultLights(); // init selector myAISContext = new AIS_InteractiveContext( myV3dViewer ); @@ -1083,6 +1088,33 @@ void OCCViewer_Viewer::performSelectionChanged() emit selectionChanged(); } +/* + * Defines default lights + */ +void OCCViewer_Viewer::setDefaultLights() +{ + // clear all light sources + myV3dViewer->InitDefinedLights(); + while ( myV3dViewer->MoreDefinedLights() ) + { + myV3dViewer->DelLight( myV3dViewer->DefinedLight() ); + myV3dViewer->InitDefinedLights(); + } + + // get light source parameters from preferences + QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) ); + double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 ); + double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 ); + double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 ); + + Handle(V3d_DirectionalLight) aLight = + new V3d_DirectionalLight( myV3dViewer, V3d_Zneg, CAF_Tools::color( aColor ).Name(), Standard_True ); + if( !( aDx == 0 && aDy == 0 && aDz == 0 ) ) + aLight->SetDirection( aDx, aDy, aDz ); + myV3dViewer->SetLightOn( aLight ); + myV3dViewer->SetLightOn( new V3d_AmbientLight( myV3dViewer ) ); +} + /*! Hilights/unhilights object in viewer \param obj - object to be updated diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index a8eba563e..09d071fce 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -100,6 +100,8 @@ public: void performSelectionChanged(); // emit signal selectionChanged + void setDefaultLights(); + QColor backgroundColor() const; // obsolete void setBackgroundColor( const QColor& ); // obsolete Qtx::BackgroundData background() const; diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index cc6d7bf5a..5e927fbb3 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include @@ -88,7 +90,7 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V } #endif - setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background + setDefaultParams(); myCursor = NULL; } @@ -803,3 +805,26 @@ QCursor* OCCViewer_ViewPort3d::getDefaultCursor() const { return myCursor; } + +/* + * Set default parameters from preferences + */ +void OCCViewer_ViewPort3d::setDefaultParams() +{ + setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background + + // get ray tracing parameters from preferences + int aDepth = SUIT_Session::session()->resourceMgr()->integerValue( "OCCViewer", "rt_depth", 3 ); + bool aReflection = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_reflection", true ); + bool anAntialiasing = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_antialiasing", false ); + bool aShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_shadow", true ); + bool aTransparentShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_trans_shadow", true ); + + Graphic3d_RenderingParams& aParams = myActiveView->ChangeRenderingParams(); + aParams.RaytracingDepth = aDepth; + aParams.IsReflectionEnabled = aReflection; + aParams.IsAntialiasingEnabled = anAntialiasing; + aParams.IsShadowEnabled = aShadow; + aParams.IsTransparentShadowEnabled = aTransparentShadow; + myActiveView->Redraw(); +} diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 7f8841a25..1413b76e9 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -122,6 +122,7 @@ private: bool setWindow( const Handle(V3d_View)& ); bool mapped( const Handle(V3d_View)& ) const; void updateBackground(); + void setDefaultParams(); private: Handle(V3d_View) myActiveView; diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index a0e96792b..d8c9de76b 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -34,6 +34,10 @@ #include "OCCViewer_AxialScaleDlg.h" #include "OCCViewer_CubeAxesDlg.h" #include "OCCViewer_ClippingDlg.h" +#include "OCCViewer_RayTracingDlg.h" +#include "OCCViewer_EnvTextureDlg.h" +#include "OCCViewer_LightSourceDlg.h" +#include "OCCViewer_Utilities.h" #include #include @@ -116,6 +120,9 @@ static QEvent* l_mbPressEvent = 0; #undef KeyPress #endif +// Enable ray tracing features +#define ENABLE_RAY_TRACING + const char* imageZoomCursor[] = { "32 32 3 1", ". c None", @@ -1446,6 +1453,28 @@ void OCCViewer_ViewWindow::createActions() // Synchronize View toolMgr()->registerAction( synchronizeAction(), SynchronizeId ); +#ifdef ENABLE_RAY_TRACING + // Ray tracing + aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ), + tr("MNU_RAY_TRACING"), 0, this ); + aAction->setStatusTip( tr("DSC_RAY_TRACING") ); + connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) ); + toolMgr()->registerAction( aAction, RayTracingId ); + + // Environment texture + aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ), + tr("MNU_ENV_TEXTURE"), 0, this ); + aAction->setStatusTip( tr("DSC_ENV_TEXTURE") ); + connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) ); + toolMgr()->registerAction( aAction, EnvTextureId ); + + // Light source + aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ), + tr( "MNU_LIGHT_SOURCE" ), 0, this ); + aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") ); + connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) ); + toolMgr()->registerAction( aAction, LightSourceId ); +#endif } /*! @@ -1535,6 +1564,11 @@ void OCCViewer_ViewWindow::createToolBar() toolMgr()->append( MaximizedId, tid ); toolMgr()->append( SynchronizeId, tid ); +#ifdef ENABLE_RAY_TRACING + toolMgr()->append( RayTracingId, tid ); + toolMgr()->append( EnvTextureId, tid ); + toolMgr()->append( LightSourceId, tid ); +#endif } /*! @@ -2232,17 +2266,20 @@ bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format ) { + bool res = false; + QApplication::setOverrideCursor( Qt::WaitCursor ); if ( format != "PS" && format != "EPS") - return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format ); + res = myViewPort->getView()->Dump( fileName.toStdString().c_str() ); Handle(Visual3d_View) a3dView = myViewPort->getView()->View(); if (format == "PS") - a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript); + res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript); else if (format == "EPS") - a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript); + res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript); - return true; + QApplication::restoreOverrideCursor(); + return res; } @@ -2540,6 +2577,58 @@ QString OCCViewer_ViewWindow::getVisualParameters() data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX ); data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY ); data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ ); + + // ray tracing parameters + Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams(); + if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) { + QString RayTracing = "rayTracing="; + RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth ); + RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled ); + RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled ); + RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled ); + RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled ); + data << RayTracing; + } + + // environment texture parameters + Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv(); + if ( !aTexture.IsNull() ) { + QString EnvTexture = "envTexture="; + if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) { + TCollection_AsciiString aFileName; + aTexture->Path().SystemName( aFileName ); + EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() ); + } + else + EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() ); + data << EnvTexture; + } + + // light source parameters + myModel->getViewer3d()->InitDefinedLights(); + while ( myModel->getViewer3d()->MoreDefinedLights() ) + { + Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight(); + if ( aLight->Type() != V3d_AMBIENT ) { + QString LightSource = QString( "lightSource=" ); + LightSource += QString( "lightType~%1;" ).arg( aLight->Type() ); + double aX, aY, aZ; + if ( aLight->Type() == V3d_DIRECTIONAL ) + Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ ); + else if ( aLight->Type() == V3d_POSITIONAL ) + Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ ); + LightSource += QString( "lightX~%1;" ).arg( aX ); + LightSource += QString( "lightY~%1;" ).arg( aY ); + LightSource += QString( "lightZ~%1;" ).arg( aZ ); + LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() ); + LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() ); + LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() ); + LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() ); + data << LightSource; + } + myModel->getViewer3d()->NextDefinedLights(); + } + QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" ); data << QString( "background=%1" ).arg( bg ); @@ -2658,6 +2747,81 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters ) else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt(); else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt(); else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt(); + else if ( paramName == "rayTracing" ) + { + Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams(); + rendParams.Method = Graphic3d_RM_RAYTRACING; + QStringList rtData = paramValue.split( ';' ); + foreach( QString rtParam, rtData ) + { + QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed(); + QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed(); + if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt(); + else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt(); + else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt(); + else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt(); + else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt(); + } + } + else if ( paramName == "envTexture" ) + { + Handle(Graphic3d_TextureEnv) aTexture; + QStringList etData = paramValue.split( ';' ); + foreach( QString etParam, etData ) + { + QString et_paramName = etParam.section( '~', 0, 0 ).trimmed(); + QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed(); + if ( et_paramName == "etNumber" ) + aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) ); + else if ( et_paramName == "etFile" ) + aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) ); + Handle(V3d_View) aView = this->getViewPort()->getView(); + aView->SetTextureEnv( aTexture ); + aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT ); + } + } + else if ( paramName == "lightSource" ) + { + myModel->getViewer3d()->InitDefinedLights(); + while ( myModel->getViewer3d()->MoreDefinedLights() ) + { + Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight(); + if( aLight->Type() != V3d_AMBIENT ) + myModel->getViewer3d()->DelLight( aLight ); + myModel->getViewer3d()->NextDefinedLights(); + } + double aX, aY, aZ; + double cR, cG, cB; + V3d_TypeOfLight aType; + bool isHeadlight; + QStringList lsData = paramValue.split( ';' ); + foreach( QString lsParam, lsData ) + { + QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed(); + QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed(); + if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() ); + else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble(); + else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt(); + } + Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB ); + if( aType == V3d_DIRECTIONAL ) { + Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() ); + aLight->SetDirection( aX, aY, aZ ); + aLight->SetColor( aColor ); + aLight->SetHeadlight( isHeadlight ); + myModel->getViewer3d()->SetLightOn( aLight ); + } + else if( aType == V3d_POSITIONAL ) { + Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() ); + aLight->SetHeadlight( isHeadlight ); + myModel->getViewer3d()->SetLightOn( aLight ); + } + } else if ( paramName == "background" ) { QString bg = paramValue.replace( "$", "=" ); bgData = Qtx::stringToBackground( bg ); @@ -3559,3 +3723,30 @@ void OCCViewer_ViewWindow::onClipping (bool theIsOn) } } } + +void OCCViewer_ViewWindow::onRayTracing() +{ + if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) { + QDialog* aDlg = new OCCViewer_RayTracingDlg( this ); + if ( aDlg != NULL ) + aDlg->show(); + } +} + +void OCCViewer_ViewWindow::onEnvTexture() +{ + if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) { + QDialog* aDlg = new OCCViewer_EnvTextureDlg( this ); + if ( aDlg != NULL ) + aDlg->show(); + } +} + +void OCCViewer_ViewWindow::onLightSource() +{ + if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) { + QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel ); + if ( aDlg != NULL ) + aDlg->show(); + } +} diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index 51f6b92b0..a9f656257 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -151,7 +151,7 @@ public: SwitchInteractionStyleId, SwitchZoomingStyleId, SwitchPreselectionId, SwitchSelectionId, MaximizedId, SynchronizeId, ReturnTo3dViewId, - OrthographicId, PerspectiveId, StereoId, + OrthographicId, PerspectiveId, StereoId, RayTracingId, EnvTextureId, LightSourceId, UserId }; enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, @@ -305,6 +305,9 @@ public slots: virtual void onSwitchZoomingStyle( bool on ); virtual void onSwitchPreselection( bool on ); virtual void onSwitchSelection( bool on ); + virtual void onRayTracing(); + virtual void onEnvTexture(); + virtual void onLightSource(); virtual void activateSetRotationGravity(); virtual void activateSetRotationSelected( double theX, double theY, double theZ ); diff --git a/src/OCCViewer/resources/OCCViewer_images.ts b/src/OCCViewer/resources/OCCViewer_images.ts index ee8fbb6a0..d91f20aaf 100644 --- a/src/OCCViewer/resources/OCCViewer_images.ts +++ b/src/OCCViewer/resources/OCCViewer_images.ts @@ -151,5 +151,17 @@ ICON_OCCVIEWER_STEREO occ_view_stereo.png + + ICON_OCCVIEWER_RAY_TRACING + occ_view_ray_tracing.png + + + ICON_OCCVIEWER_ENV_TEXTURE + occ_view_env_texture.png + + + ICON_OCCVIEWER_LIGHT_SOURCE + occ_view_light_source.png + diff --git a/src/OCCViewer/resources/OCCViewer_msg_en.ts b/src/OCCViewer/resources/OCCViewer_msg_en.ts index 5c993519b..36cd063ca 100644 --- a/src/OCCViewer/resources/OCCViewer_msg_en.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_en.ts @@ -276,6 +276,30 @@ DSC_RETURN_3D_VIEW Return to 3D view + + MNU_RAY_TRACING + Ray tracing + + + DSC_RAY_TRACING + Ray tracing + + + MNU_ENV_TEXTURE + Environment texture + + + DSC_ENV_TEXTURE + Environment texture + + + MNU_LIGHT_SOURCE + Light source + + + DSC_LIGHT_SOURCE + Light source + OCC_IMAGE_FILES Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps) @@ -619,4 +643,113 @@ &Help + + OCCViewer_RayTracingDlg + + RAY_TRACING + Ray tracing + + + DEPTH + Depth + + + SHADOW + Shadows rendering + + + REFLECTION + Specular reflections + + + ANTIALIASING + Adaptive anti-aliasing + + + TRANSPARENT_SHADOW + Transparent shadow + + + + OCCViewer_EnvTextureDlg + + ENV_TEXTURE + Environment texture + + + ENV_CLOUDS + Clouds + + + ENV_CV + Cv + + + ENV_MEDIT + Medit + + + ENV_PEARL + Pearl + + + ENV_SKY1 + Sky1 + + + ENV_SKY2 + Sky2 + + + ENV_LINES + Lines + + + ENV_ROAD + Road + + + ENV_CUSTOM + Custom... + + + + OCCViewer_LightSourceDlg + + LIGHT_SOURCE + Light source + + + TYPE + Type + + + DIRECTIONAL + Directional + + + DIRECTION + Direction + + + POSITIONAL + Positional + + + POSITION + Position + + + COLOR + Color + + + HEADLIGHT + Headlight + + + BUT_DEFAULT + Default + + diff --git a/src/OCCViewer/resources/OCCViewer_msg_fr.ts b/src/OCCViewer/resources/OCCViewer_msg_fr.ts index e7b680e0b..b0fd983fc 100755 --- a/src/OCCViewer/resources/OCCViewer_msg_fr.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_fr.ts @@ -275,6 +275,30 @@ DSC_RETURN_3D_VIEW Retour à la vue 3D + + MNU_RAY_TRACING + Ray tracing + + + DSC_RAY_TRACING + Ray tracing + + + MNU_ENV_TEXTURE + Environment texture + + + DSC_ENV_TEXTURE + Environment texture + + + MNU_LIGHT_SOURCE + Light source + + + DSC_LIGHT_SOURCE + Light source + OCC_IMAGE_FILES Fichiers images (*.bmp *.png *.jpg *.jpeg *.eps *.ps) @@ -618,4 +642,113 @@ Ai&de + + OCCViewer_RayTracingDlg + + RAY_TRACING + Ray tracing + + + DEPTH + Depth + + + SHADOW + Shadows rendering + + + REFLECTION + Specular reflections + + + ANTIALIASING + Adaptive anti-aliasing + + + TRANSPARENT_SHADOW + Transparent shadow + + + + OCCViewer_EnvTextureDlg + + ENV_TEXTURE + Environment texture + + + ENV_CLOUDS + Clouds + + + ENV_CV + Cv + + + ENV_MEDIT + Medit + + + ENV_PEARL + Pearl + + + ENV_SKY1 + Sky1 + + + ENV_SKY2 + Sky2 + + + ENV_LINES + Lines + + + ENV_ROAD + Road + + + ENV_CUSTOM + Custom... + + + + OCCViewer_LightSourceDlg + + LIGHT_SOURCE + Light source + + + TYPE + Type + + + DIRECTIONAL + Directional + + + DIRECTION + Direction + + + POSITIONAL + Positional + + + POSITION + Position + + + COLOR + Color + + + HEADLIGHT + Headlight + + + BUT_DEFAULT + Default + + diff --git a/src/OCCViewer/resources/OCCViewer_msg_ja.ts b/src/OCCViewer/resources/OCCViewer_msg_ja.ts index a98424954..c45ce44c6 100644 --- a/src/OCCViewer/resources/OCCViewer_msg_ja.ts +++ b/src/OCCViewer/resources/OCCViewer_msg_ja.ts @@ -272,6 +272,30 @@ MNU_RETURN_3D_VIEW 3D に戻る + + MNU_RAY_TRACING + Ray tracing + + + DSC_RAY_TRACING + Ray tracing + + + MNU_ENV_TEXTURE + Environment texture + + + DSC_ENV_TEXTURE + Environment texture + + + MNU_LIGHT_SOURCE + Light source + + + DSC_LIGHT_SOURCE + Light source + DSC_RETURN_3D_VIEW 3D view に戻る @@ -619,4 +643,113 @@ ヘルプ(&H) + + OCCViewer_RayTracingDlg + + RAY_TRACING + Ray tracing + + + DEPTH + Depth + + + SHADOW + Shadows rendering + + + REFLECTION + Specular reflections + + + ANTIALIASING + Adaptive anti-aliasing + + + TRANSPARENT_SHADOW + Transparent shadow + + + + OCCViewer_EnvTextureDlg + + ENV_TEXTURE + Environment texture + + + ENV_CLOUDS + Clouds + + + ENV_CV + Cv + + + ENV_MEDIT + Medit + + + ENV_PEARL + Pearl + + + ENV_SKY1 + Sky1 + + + ENV_SKY2 + Sky2 + + + ENV_LINES + Lines + + + ENV_ROAD + Road + + + ENV_CUSTOM + Custom... + + + + OCCViewer_LightSourceDlg + + LIGHT_SOURCE + Light source + + + TYPE + Type + + + DIRECTIONAL + Directional + + + DIRECTION + Direction + + + POSITIONAL + Positional + + + POSITION + Position + + + COLOR + Color + + + HEADLIGHT + Headlight + + + BUT_DEFAULT + Default + + diff --git a/src/OCCViewer/resources/occ_view_env_texture.png b/src/OCCViewer/resources/occ_view_env_texture.png new file mode 100644 index 000000000..e360a879f Binary files /dev/null and b/src/OCCViewer/resources/occ_view_env_texture.png differ diff --git a/src/OCCViewer/resources/occ_view_light_source.png b/src/OCCViewer/resources/occ_view_light_source.png new file mode 100644 index 000000000..e6cbf6880 Binary files /dev/null and b/src/OCCViewer/resources/occ_view_light_source.png differ diff --git a/src/OCCViewer/resources/occ_view_ray_tracing.png b/src/OCCViewer/resources/occ_view_ray_tracing.png new file mode 100644 index 000000000..fc64a1341 Binary files /dev/null and b/src/OCCViewer/resources/occ_view_ray_tracing.png differ