From 1e79bc9837ed4bf66383139ae7d5b94f7ebd0259 Mon Sep 17 00:00:00 2001 From: mpa Date: Thu, 11 Sep 2014 12:57:05 +0400 Subject: [PATCH] 0021791: [CEA 623] Clipping : no difference between a closed shell and a solid. - added texture(hatch) for capping --- src/OCCViewer/CMakeLists.txt | 10 +++- src/OCCViewer/OCCViewer.qrc | 5 ++ src/OCCViewer/OCCViewer_Utilities.cxx | 69 ++++++++++++++++++++++++++ src/OCCViewer/OCCViewer_Utilities.h | 36 ++++++++++++++ src/OCCViewer/OCCViewer_ViewModel.cxx | 17 +++++++ src/OCCViewer/images/hatch.png | Bin 0 -> 5578 bytes 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/OCCViewer/OCCViewer.qrc create mode 100755 src/OCCViewer/OCCViewer_Utilities.cxx create mode 100755 src/OCCViewer/OCCViewer_Utilities.h create mode 100644 src/OCCViewer/images/hatch.png diff --git a/src/OCCViewer/CMakeLists.txt b/src/OCCViewer/CMakeLists.txt index e9627c893..c1476ed93 100755 --- a/src/OCCViewer/CMakeLists.txt +++ b/src/OCCViewer/CMakeLists.txt @@ -77,6 +77,7 @@ SET(_other_HEADERS OCCViewer_ClipPlane.h OCCViewer_Trihedron.h OCCViewer_VService.h + OCCViewer_Utilities.h ) # header files / no moc processing / internal @@ -90,6 +91,9 @@ SET(OCCViewer_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) # --- resources --- +# resource files / to be processed by rcc +SET(_rcc_RESOURCES OCCViewer.qrc) + # resource files / to be processed by lrelease SET(_ts_RESOURCES resources/OCCViewer_images.ts @@ -140,6 +144,9 @@ SET(_other_RESOURCES # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) +# sources / rcc wrappings +QT4_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) + # sources / static SET(_other_SOURCES OCCViewer_AISSelector.cxx @@ -162,10 +169,11 @@ SET(_other_SOURCES OCCViewer_ViewWindow.cxx OCCViewer_ViewportInputFilter.cxx OCCViewer_ClipPlaneInteractor.cxx + OCCViewer_Utilities.cxx ) # sources / to compile -SET(OCCViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) +SET(OCCViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES} ${_rcc_SOURCES}) # --- rules --- diff --git a/src/OCCViewer/OCCViewer.qrc b/src/OCCViewer/OCCViewer.qrc new file mode 100644 index 000000000..cc4c1671d --- /dev/null +++ b/src/OCCViewer/OCCViewer.qrc @@ -0,0 +1,5 @@ + + + images/hatch.png + + diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx new file mode 100755 index 000000000..4d8de5fbb --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@ -0,0 +1,69 @@ +// Copyright (C) 2014 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_Utilities.h" + +// KERNEL includes +#include + +// OCC Includes +#include + +// QT includes +#include + +/*! Concert QImage to OCCT pixmap*/ +Handle(Image_PixMap) +imageToPixmap( const QImage& anImage ) +{ + Handle(Image_PixMap) aPixmap = new Image_PixMap(); + if ( !anImage.isNull() ) { + aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() ); + aPixmap->SetTopDown( Standard_True ); + + const uchar* aImageBytes = anImage.bits(); + + for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) { +#if OCC_VERSION_LARGE > 0x06070100 + // convert pixels from ARGB to renderer-compatible RGBA + for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { + Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue(aLine, aByte); + + aPixmapBytes.b() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.g() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.r() = (Standard_Byte) *aImageBytes++; + aPixmapBytes.a() = (Standard_Byte) *aImageBytes++; + } +#else + Image_ColorBGRA* aPixmapBytes = aPixmap->EditData().ChangeRow(aLine); + + // convert pixels from ARGB to renderer-compatible RGBA + for ( int aByte = 0; aByte < anImage.width(); ++aByte ) { + aPixmapBytes->b() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->g() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->r() = (Standard_Byte) *aImageBytes++; + aPixmapBytes->a() = (Standard_Byte) *aImageBytes++; + aPixmapBytes++; + } +#endif + } + } + return aPixmap; +} diff --git a/src/OCCViewer/OCCViewer_Utilities.h b/src/OCCViewer/OCCViewer_Utilities.h new file mode 100755 index 000000000..c745da015 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014 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_UTILITIES_H +#define OCCVIEWER_UTILITIES_H + +// internal includes +#include "OCCViewer.h" + +// OCC includes +#include + +class QImage; + +OCCVIEWER_EXPORT +extern +Handle(Image_PixMap) +imageToPixmap( const QImage& anImage ); + +#endif diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 7300cebec..5aff3c60d 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -26,6 +26,7 @@ #include "OCCViewer_VService.h" #include "OCCViewer_ViewPort3d.h" #include "OCCViewer_ClippingDlg.h" +#include "OCCViewer_Utilities.h" #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" @@ -54,6 +55,9 @@ #include #include +#include +#include + #include #include #include @@ -1039,6 +1043,19 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane ); aGraphic3dPlane->SetOn( theIsOn ); aGraphic3dPlane->SetCapping( Standard_True ); + + // load capping texture + QPixmap px( ":images/hatch.png" ); + if( !px.isNull() ) { + const Handle(Image_PixMap) aPixmap = imageToPixmap( px.toImage() ); + Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap ); + if( aTexture->IsDone() ) { + aTexture->EnableModulate(); + aTexture->EnableRepeat(); + aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.01, 0.01 ) ); + aGraphic3dPlane->SetCappingTexture( aTexture ); + } + } return aGraphic3dPlane; } /*! diff --git a/src/OCCViewer/images/hatch.png b/src/OCCViewer/images/hatch.png new file mode 100644 index 0000000000000000000000000000000000000000..97232a79af5d466879544fc2df1dd452dd59078e GIT binary patch literal 5578 zcmeI0TS${(7{|X3I4!r?8FQ|vsIDrQSk|nR$+F0G@J7haHH6S?vo?>|MROn&coBuo zpo>vNQqn;xB^G(%VbID_Gh0%tmN{KkmTAlF`9DG{=>B`hkUgK@yWji#|L^lXd#&3t zw9;wwrwM`}P2Z&1AqbNrf4?Im0+Hz>a}NamOfu}yrV7{E6z>BcBKB|5YJ{=huZ#EX zRe?y<(M?$fL6B7k-UX8?mdBX_L5VSaYntR`)bz-i(nNb+mLSa8oUTd9G3Gp80m5z=6^n0Jx)_gBhjt^V5`n4}Ojzmw*HwDM}@`W<__|O^XvT+%OhBS)M%^$35 z)WPv|7TtSg8Qqbod*}|1%eD$faO~VevDn;&p`gl!TcTAlq3f~FFyo2^k)bIo`|*Wm zr9}I706Z?q$qQ-w=QrCt5HUVhtg(Q=%gc$U9=$oA;XrpR@HoKrr zeKDm%)c_0af;Q)xV4)0HsD(3bXA7~V9mu%9h}fL_V4(um;VUo;fmzoD%xqu|7ZPS2 zV-~APrux%hzn6?)4F~x@YY|k(li7T5e=7m~MX_#TvrI@kuUw*}Exh(LDS9D{S#BXi z>Q!3Bs9xX}GiurIBIXa9=NP?^VzyA2WIeDHYCd(8ka~w0b49Ny7G4 zamK6JLcG0YY$4v>7FejAt57!*c1%+i4Z=u6-k4}-^5O}6T$+OZS42y4l3H2i#d zGLH;iCFl)r?g1^7cMNv^F!gx92moDMoS)os@C?Znh9tp+@Xa1uT@s zRp>Y@bd@phvV|D47MNbfYy##F6G~GT2ia`R97KV2x@bXipm!)JZ+}q?Y$i@SKi18! zsAltX!)5-{EC-9&0}#a|HW{n~s*u=ZxWy(zY%+9WlOZ-4KC#Kb6Cz1$GAv?~fwoRO x$*@>F;zPVdiwWCM!SE*(3v-VFP1)@9XMze($g|D*HZVM`~{EOgyjGL literal 0 HcmV?d00001 -- 2.39.2