1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include "VISU_GaussPoints_i.hh"
28 #include "VISU_ScalarMap_i.hh"
30 #include "VISU_Result_i.hh"
31 #include "VISU_GaussPtsAct.h"
32 #include "VISU_GaussPointsPL.hxx"
33 #include "VVTK_SegmentationCursorDlg.h"
35 #include "VISU_OpenGLPointSpriteMapper.hxx"
36 #include "VISU_ScalarBarCtrl.hxx"
38 #include "SUIT_ResourceMgr.h"
40 #include <vtkImageData.h>
41 #include <vtkXMLImageDataReader.h>
42 #include <vtkScalarBarActor.h>
43 #include <vtkTextProperty.h>
44 #include <vtkProperty.h>
50 static int MYDEBUG = 0;
52 static int MYDEBUG = 0;
55 //----------------------------------------------------------------------------
58 ::IsPossible(Result_i* theResult,
59 const char* theMeshName,
60 VISU::Entity theEntity,
61 const char* theFieldName,
66 if(theEntity != VISU::NODE)
67 return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck);
70 }catch(std::exception& exc){
71 INFOS("Follow exception was occured :\n"<<exc.what());
73 INFOS("Unknown exception was occured!");
78 //----------------------------------------------------------------------------
79 int VISU::GaussPoints_i::myNbPresent = 0;
85 return VISU::GenerateName("Gauss Points",myNbPresent++);
88 //----------------------------------------------------------------------------
89 const string VISU::GaussPoints_i::myComment = "GAUSSPOINTS";
95 return myComment.c_str();
99 //----------------------------------------------------------------------------
100 VISU::GaussPoints_i::
101 GaussPoints_i(Result_i* theResult,
102 bool theAddToStudy) :
103 PrsObject_i(theResult->GetStudyDocument()),
104 Prs3d_i(theResult,theAddToStudy),
105 ColoredPrs3d_i(theResult,theAddToStudy),
106 myGaussPointsPL(NULL),
109 myIsActiveLocalScalarBar(true),
110 myIsDispGlobalScalarBar(true),
114 if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<<this);
118 //----------------------------------------------------------------------------
119 VISU::GaussPoints_i::
120 GaussPoints_i(Result_i* theResult,
121 SALOMEDS::SObject_ptr theSObject) :
122 PrsObject_i(theResult->GetStudyDocument()),
123 Prs3d_i(theResult,theSObject),
124 ColoredPrs3d_i(theResult,theSObject),
125 myGaussPointsPL(NULL),
128 myIsActiveLocalScalarBar(true),
129 myIsDispGlobalScalarBar(true),
132 if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<<this);
136 //----------------------------------------------------------------------------
139 ::Create(const char* theMeshName,
140 VISU::Entity theEntity,
141 const char* theFieldName,
144 TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration);
146 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
148 int anActiveLocal = aResourceMgr->integerValue( "VISU", "scalar_bar_active_local", GetIsActiveLocalScalarBar() );
149 SetIsActiveLocalScalarBar( anActiveLocal == 0 );
151 bool aDisplayGlobal = aResourceMgr->booleanValue( "VISU", "scalar_bar_diplay_global", GetIsDispGlobalScalarBar() );
152 SetIsDispGlobalScalarBar( aDisplayGlobal );
154 int aBicolor = aResourceMgr->integerValue( "VISU", "scalar_bar_bicolor", GetBiColor() );
155 SetBiColor( aBicolor == 0 );
157 vtkFloatingPointType aSpacing = aResourceMgr->doubleValue( "VISU", "scalar_bar_spacing", GetSpacing() );
158 SetSpacing( aSpacing );
160 vtkFloatingPointType aScaleFactor = aResourceMgr->doubleValue( "VISU", "deformed_shape_scale_factor", GetScaleFactor() );
161 SetScaleFactor( aScaleFactor );
163 int aPrimitiveType = aResourceMgr->integerValue( "VISU", "point_sprite_primitive_type", GetPrimitiveType() );
164 SetPrimitiveType( aPrimitiveType );
166 vtkFloatingPointType aClamp = aResourceMgr->doubleValue( "VISU", "point_sprite_clamp", GetClamp() );
169 int aMinSize = aResourceMgr->integerValue( "VISU", "point_sprite_min_size", ( int )( GetMinSize() * 100.0 ) );
170 SetMinSize( aMinSize / 100.0 );
172 int aMaxSize = aResourceMgr->integerValue( "VISU", "point_sprite_max_size", ( int )( GetMaxSize() * 100.0 ) );
173 SetMaxSize( aMaxSize / 100.0 );
175 int aGeomSize = aResourceMgr->integerValue( "VISU", "point_sprite_size", ( int )( GetGeomSize() * 100.0 ) );
176 SetGeomSize( aGeomSize / 100.0 );
178 int aMagnification = aResourceMgr->integerValue( "VISU", "point_sprite_magnification", ( int )( GetMagnification() * 100.0 ) );
179 SetMagnification( aMagnification / 100.0 );
181 vtkFloatingPointType anIncrement = aResourceMgr->doubleValue( "VISU", "point_sprite_increment", GetMagnificationIncrement() );
182 SetMagnificationIncrement( anIncrement );
184 bool isColored = aResourceMgr->booleanValue( "VISU", "point_sprite_results", GetIsColored() );
185 SetIsColored( isColored );
187 QColor aColor = aResourceMgr->colorValue( "VISU", "point_sprite_color", GetColor() );
190 vtkFloatingPointType anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "point_sprite_alpha_threshold", GetAlphaThreshold() );
191 SetAlphaThreshold( anAlphaThreshold );
193 int aResolution = aResourceMgr->integerValue( "VISU", "geom_sphere_resolution", GetResolution() );
194 SetResolution( aResolution );
196 int aFaceLimit = aResourceMgr->integerValue( "VISU", "geom_sphere_face_limit", GetFaceLimit() );
197 SetFaceLimit( aFaceLimit );
199 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
200 aMainTexture = aResourceMgr->stringValue( "VISU", "point_sprite_main_texture", aMainTexture );
202 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
203 anAlphaTexture = aResourceMgr->stringValue( "VISU", "point_sprite_alpha_texture", anAlphaTexture );
205 SetTextures( aMainTexture, anAlphaTexture );
211 //----------------------------------------------------------------------------
214 ::Restore(const Storable::TRestoringMap& theMap)
216 TSuperClass::Restore(theMap);
218 SetIsActiveLocalScalarBar(Storable::FindValue(theMap,"myIsActiveLocalScalarBar").toInt());
219 SetIsDispGlobalScalarBar(Storable::FindValue(theMap,"myIsDispGlobalScalarBar").toInt());
220 SetBiColor(Storable::FindValue(theMap,"myIsBiColor").toInt());
221 SetSpacing(Storable::FindValue(theMap,"mySpacing").toDouble());
223 SetPrimitiveType(Storable::FindValue(theMap,"myPrimitiveType").toInt());
224 SetClamp(Storable::FindValue(theMap,"myClamp").toDouble());
225 SetMinSize(Storable::FindValue(theMap,"myMinSize").toDouble());
226 SetMaxSize(Storable::FindValue(theMap,"myMaxSize").toDouble());
227 SetGeomSize(Storable::FindValue(theMap,"myGeomSize").toDouble());
229 SetMagnification(Storable::FindValue(theMap,"myMagnification").toDouble());
230 SetMagnificationIncrement(Storable::FindValue(theMap,"myMagnificationIncrement").toDouble());
232 SetIsDeformed(Storable::FindValue(theMap,"myIsDeformed").toInt());
233 SetScaleFactor(Storable::FindValue(theMap,"myScaleFactor").toDouble());
235 SetFaceLimit(Storable::FindValue(theMap,"myFaceLimit").toInt());
237 SetIsColored(Storable::FindValue(theMap,"myIsColored").toInt());
238 int aRed = Storable::FindValue(theMap,"myColor.R").toInt();
239 int aGreen = Storable::FindValue(theMap,"myColor.G").toInt();
240 int aBlue = Storable::FindValue(theMap,"myColor.B").toInt();
241 SetColor( QColor(aRed,aGreen,aBlue) );
243 SetAlphaThreshold(Storable::FindValue(theMap,"myAlphaThreshold").toDouble());
245 SetTextures( Storable::FindValue(theMap,"myMainTexture"),
246 Storable::FindValue(theMap,"myAlphaTexture") );
248 SetResolution(Storable::FindValue(theMap,"myResolution").toInt());
254 //----------------------------------------------------------------------------
257 ::ToStream(std::ostringstream& theStr)
259 TSuperClass::ToStream(theStr);
261 Storable::DataToStream( theStr, "myIsActiveLocalScalarBar", myIsActiveLocalScalarBar );
262 Storable::DataToStream( theStr, "myIsDispGlobalScalarBar", myIsDispGlobalScalarBar );
263 Storable::DataToStream( theStr, "myIsBiColor", GetBiColor() );
264 Storable::DataToStream( theStr, "mySpacing", GetSpacing() );
266 Storable::DataToStream( theStr, "myPrimitiveType", GetPrimitiveType() );
267 Storable::DataToStream( theStr, "myClamp", GetClamp() );
268 Storable::DataToStream( theStr, "myMinSize", GetMinSize() );
269 Storable::DataToStream( theStr, "myMaxSize", GetMaxSize() );
270 Storable::DataToStream( theStr, "myGeomSize", GetGeomSize() );
272 Storable::DataToStream( theStr, "myMagnification", GetMagnification() );
273 Storable::DataToStream( theStr, "myMagnificationIncrement", GetMagnificationIncrement() );
275 Storable::DataToStream( theStr, "myIsDeformed", GetIsDeformed() );
276 Storable::DataToStream( theStr, "myScaleFactor", GetScaleFactor() );
278 Storable::DataToStream( theStr, "myFaceLimit", GetFaceLimit() );
280 Storable::DataToStream( theStr, "myIsColored", GetIsColored() );
281 QColor aColor = GetColor();
282 Storable::DataToStream( theStr, "myColor.R", aColor.red() );
283 Storable::DataToStream( theStr, "myColor.G", aColor.green() );
284 Storable::DataToStream( theStr, "myColor.B", aColor.blue() );
286 Storable::DataToStream( theStr, "myAlphaThreshold", GetAlphaThreshold() );
287 Storable::DataToStream( theStr, "myMainTexture", GetMainTexture() );
288 Storable::DataToStream( theStr, "myAlphaTexture", GetAlphaTexture() );
290 Storable::DataToStream( theStr, "myResolution", GetResolution() );
297 if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i() - this = "<<this);
301 //----------------------------------------------------------------------------
306 return myGaussPointsPL;
311 ::SetIsDeformed( bool theIsDeformed )
313 myGaussPointsPL->SetIsDeformed( theIsDeformed );
320 return myGaussPointsPL->GetIsDeformed();
325 ::SetScaleFactor( vtkFloatingPointType theScaleFactor )
327 myGaussPointsPL->SetScale( theScaleFactor );
334 return myGaussPointsPL->GetScale();
339 ::SetIsColored( bool theIsColored )
341 myIsColored = theIsColored;
342 myGaussPointsPL->SetIsColored( theIsColored );
347 ::SetMainTexture( const QString& theMainTexture )
349 bool update = myMainTexture != theMainTexture;
350 myMainTexture = theMainTexture;
358 return myMainTexture;
363 ::SetAlphaTexture( const QString& theAlphaTexture )
365 bool update = myAlphaTexture != theAlphaTexture;
366 myAlphaTexture = theAlphaTexture;
374 return myAlphaTexture;
379 ::SetAlphaThreshold( vtkFloatingPointType theAlphaThreshold )
381 myGaussPointsPL->SetAlphaThreshold( theAlphaThreshold );
386 ::GetAlphaThreshold()
388 return myGaussPointsPL->GetAlphaThreshold();
393 ::SetResolution( int theResolution )
395 myGaussPointsPL->SetResolution( theResolution );
402 return myGaussPointsPL->GetResolution();
407 ::SetPrimitiveType(int thePrimitiveType)
409 myGaussPointsPL->SetPrimitiveType( thePrimitiveType );
416 return myGaussPointsPL->GetPrimitiveType();
421 ::GetMaximumSupportedSize()
423 return myGaussPointsPL->GetMaximumSupportedSize();
428 ::SetClamp(vtkFloatingPointType theClamp)
430 myGaussPointsPL->SetClamp( theClamp );
437 return myGaussPointsPL->GetClamp();
442 ::SetGeomSize( vtkFloatingPointType theGeomSize )
444 myGaussPointsPL->SetSize( theGeomSize );
451 return myGaussPointsPL->GetSize();
456 ::SetMinSize( vtkFloatingPointType theMinSize )
458 myGaussPointsPL->SetMinSize( theMinSize );
465 return myGaussPointsPL->GetMinSize();
470 ::SetMaxSize( vtkFloatingPointType theMaxSize )
472 myGaussPointsPL->SetMaxSize( theMaxSize );
479 return myGaussPointsPL->GetMaxSize();
484 ::SetMagnification( vtkFloatingPointType theMagnification )
486 myGaussPointsPL->SetMagnification( theMagnification );
493 return myGaussPointsPL->GetMagnification();
498 ::SetMagnificationIncrement( vtkFloatingPointType theIncrement )
500 myGaussPointsPL->SetMagnificationIncrement( theIncrement );
505 ::GetMagnificationIncrement()
507 return myGaussPointsPL->GetMagnificationIncrement();
510 //----------------------------------------------------------------------------
513 ::DoSetInput(Result_i* theResult)
515 VISU::Result_i::TInput* anInput = theResult->GetInput();
517 throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!");
519 myField = anInput->GetField(myMeshName,myEntity,myFieldName);
521 throw std::runtime_error("There is no Field with the parameters !!!");
523 VISU::PGaussPtsIDMapper aGaussPtsIDMapper =
524 anInput->GetTimeStampOnGaussPts(myMeshName,myEntity,myFieldName,myIteration);
526 if(!aGaussPtsIDMapper)
527 throw std::runtime_error("There is no TimeStamp with the parameters !!!");
529 myGaussPointsPL->SetGaussPtsIDMapper(aGaussPtsIDMapper);
530 myGaussPointsPL->Init();
531 myGaussPointsPL->Build();
533 theResult->MinMaxConnect(this);
537 //----------------------------------------------------------------------------
543 myPipeLine = VISU_GaussPointsPL::New();
545 myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(myPipeLine);
547 TSuperClass::DoHook();
551 //----------------------------------------------------------------------------
556 // We create a new PipeLine instance in order to provide
557 // different representations for different actors (basic and segmented)
558 VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
559 aPipeLine->SetGaussPtsIDMapper(myGaussPointsPL->GetGaussPtsIDMapper());
560 aPipeLine->ShallowCopy(myPipeLine);
566 //----------------------------------------------------------------------------
569 ::OnCreateActor(VISU_GaussPtsAct* theActor,
570 const Handle(SALOME_InteractiveObject)& theIO)
573 TSuperClass::CreateActor(theActor,theIO);
574 theActor->GetPipeLine()->Delete();
575 UpdateActor(theActor);
586 ::OnCreateActor1(const Handle(SALOME_InteractiveObject)& theIO)
588 VISU_GaussPtsAct1* anActor = VISU_GaussPtsAct1::New();
589 if(OnCreateActor(anActor,theIO))
596 ::OnCreateActor2(const Handle(SALOME_InteractiveObject)& theIO)
598 VISU_GaussPtsAct2* anActor = VISU_GaussPtsAct2::New();
599 if(OnCreateActor(anActor,theIO))
606 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
608 return OnCreateActor1(theIO);
611 //----------------------------------------------------------------------------
614 ::CloneActor(VISU_GaussPtsAct1* theActor)
616 if(MYDEBUG) MESSAGE("GaussPoints_i::CloneActor - this = "<<this);
617 if(VISU_GaussPtsAct2* anActor = OnCreateActor2()){
618 theActor->Connect(anActor);
625 //----------------------------------------------------------------------------
628 ::UpdateScalarBar(vtkScalarBarActor *theScalarBar,
629 vtkLookupTable* theLookupTable)
631 theScalarBar->SetTitle(myTitle.c_str());
632 theScalarBar->SetOrientation(myOrientation);
633 theScalarBar->SetNumberOfLabels(myNumberOfLabels);
635 vtkLookupTable* aLookupTable = myScalarMapPL->GetBarTable();
637 theLookupTable->SetNumberOfColors(aLookupTable->GetNumberOfColors());
638 theScalarBar->SetMaximumNumberOfColors(aLookupTable->GetNumberOfColors());
640 vtkTextProperty* aTitleProp = theScalarBar->GetTitleTextProperty();
641 aTitleProp->SetFontFamily(myTitFontType);
642 aTitleProp->SetColor(myTitleColor[0],myTitleColor[1],myTitleColor[2]);
643 (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
644 (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
645 (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
647 vtkTextProperty* aLabelProp = theScalarBar->GetLabelTextProperty();
648 aLabelProp->SetFontFamily(myLblFontType);
649 aLabelProp->SetColor(myLabelColor[0],myLabelColor[1],myLabelColor[2]);
650 (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
651 (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
652 (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
654 theScalarBar->Modified();
658 //----------------------------------------------------------------------------
661 ::UpdateActor(VISU_Actor* theActor)
663 if(VISU_GaussPtsAct* anActor = dynamic_cast<VISU_GaussPtsAct*>(theActor)){
664 VISU_ScalarBarCtrl *aScalarBarCtrl = anActor->GetScalarBarCtrl();
666 anActor->SetBarVisibility(true);
667 myPipeLine->GetMapper()->SetScalarVisibility(1);
669 vtkFloatingPointType aRange[2];
670 myScalarMapPL->GetSourceRange(aRange);
671 aScalarBarCtrl->SetRangeLocal(aRange);
673 TMinMax aTMinMax(-VTK_LARGE_FLOAT,VTK_LARGE_FLOAT);
674 bool anIsMinMaxDone = IsGlobalRangeDefined();
676 aTMinMax = myField->GetMinMax(GetScalarMode());
677 aScalarBarCtrl->SetGlobalRangeIsDefined(anIsMinMaxDone);
678 aScalarBarCtrl->SetRangeGlobal(aTMinMax.first, aTMinMax.second);
680 VISU_ScalarBarCtrl::EMode aScalarBarMode = VISU_ScalarBarCtrl::eGlobal;
681 if(myIsActiveLocalScalarBar){
682 if(myIsDispGlobalScalarBar){
683 aScalarBarMode = VISU_ScalarBarCtrl::eLocal;
685 aScalarBarMode = VISU_ScalarBarCtrl::eSimple;
689 if(aScalarBarMode == VISU_ScalarBarCtrl::eGlobal){
690 vtkFloatingPointType aRangeGlobal[2];
692 aRangeGlobal[0] = aTMinMax.first;
693 aRangeGlobal[1] = aTMinMax.second;
695 GetGaussPointsPL()->GetMapper()->SetScalarRange(aRangeGlobal);
698 aScalarBarCtrl->SetMode(aScalarBarMode);
701 aScalarBarCtrl->SetWidth(myWidth);
702 aScalarBarCtrl->SetHeight(myHeight);
703 aScalarBarCtrl->SetPosition(myPosition);
705 aScalarBarCtrl->SetSpacing(mySpacing);
708 bool anIsBicolor = GetGaussPointsPL()->GetBicolor();
709 aScalarBarCtrl->SetBicolor(anIsBicolor);
711 UpdateScalarBar(aScalarBarCtrl->GetLocalBar(),
712 aScalarBarCtrl->GetLocalTable());
714 UpdateScalarBar(aScalarBarCtrl->GetGlobalBar(),
715 aScalarBarCtrl->GetGlobalTable());
717 aScalarBarCtrl->Update();
719 anActor->SetBarVisibility(false);
721 myPipeLine->GetMapper()->SetScalarVisibility(0);
723 anActor->GetProperty()->SetColor(myColor.red() / 255.0,
724 myColor.green() / 255.0,
725 myColor.blue() / 255.0);
728 if( GetGaussPointsPL()->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
729 theActor->SetRepresentation( VTK_POINTS );
731 theActor->SetRepresentation( VTK_SURFACE );
733 TSuperClass::UpdateActor(theActor);
736 //----------------------------------------------------------------------------
739 ::UpdateFromActor(VISU_GaussPtsAct* theActor)
741 if(MYDEBUG) MESSAGE("GaussPoints_i::UpdateFromActor - this = "<<this);
742 myGaussPointsPL->ChangeMagnification(theActor->GetChangeMagnification());
747 //----------------------------------------------------------------------------
750 ::SetTextures( const QString& theMainTexture,
751 const QString& theAlphaTexture )
753 bool updateMainTexture = SetMainTexture( theMainTexture );
754 bool updateAlphaTexture = SetAlphaTexture( theAlphaTexture );
755 if( !updateMainTexture && !updateAlphaTexture )
758 using namespace VISU;
759 TTextureValue aTextureValue = GetTexture(theMainTexture,theAlphaTexture);
760 myGaussPointsPL->SetImageData( aTextureValue.GetPointer() );
764 //----------------------------------------------------------------------------
767 ::SetIsActiveLocalScalarBar(const bool theFlag)
769 myIsActiveLocalScalarBar = theFlag;
774 ::GetIsActiveLocalScalarBar() const
776 return myIsActiveLocalScalarBar;
781 ::SetIsDispGlobalScalarBar(const bool theFlag)
783 myIsDispGlobalScalarBar=theFlag;
788 ::IsGlobalRangeDefined() const
790 return myResult->IsMinMaxDone();
795 ::GetIsDispGlobalScalarBar() const
797 return myIsDispGlobalScalarBar;
802 ::SetBiColor(bool theIsBiColor)
804 GetGaussPointsPL()->SetBicolor(theIsBiColor);
811 return GetGaussPointsPL()->GetBicolor();
816 ::SetSpacing(const vtkFloatingPointType theSpacing)
818 mySpacing = theSpacing;
828 //----------------------------------------------------------------------------
833 MinMaxCunsomer::UpdateMinMax();