From 2d65731d25d111c21f758052d871b03d3801211a Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 23 Sep 2005 05:53:06 +0000 Subject: [PATCH] To implement automatic Actors destruction by connection VISU_Actor::RemoveFromRenderer method on corresponding signal --- src/VISU_I/VISU_GaussPoints_i.cc | 124 +++++++++++++------------------ src/VISU_I/VISU_Mesh_i.cc | 2 +- src/VISU_I/VISU_Prs3d_i.cc | 46 +++++++++--- src/VISU_I/VISU_Prs3d_i.hh | 52 +++++++------ src/VISU_I/VISU_ScalarMap_i.cc | 2 +- 5 files changed, 119 insertions(+), 107 deletions(-) diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index ff778906..c15f49d6 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -30,9 +30,11 @@ #include "VISU_GaussPtsAct.h" #include "VISU_GaussPointsPL.hxx" - #include "VISU_OpenGLPointSpriteMapper.hxx" +#include +#include + using namespace VISU; using namespace std; @@ -42,9 +44,6 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif -#include -#include - //---------------------------------------------------------------------------- int VISU::GaussPoints_i @@ -100,7 +99,7 @@ GaussPoints_i(Result_i* theResult, myIsColored(true), myColor(Qt::blue) { - if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i"); + if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<SetFileName( theMainTexture ); + anAlphaReader->SetFileName( theAlphaChannelTexture ); + + aMainReader->Update(); + anAlphaReader->Update(); + + vtkImageData* aMainImageData = aMainReader->GetOutput(); + vtkImageData* anAlphaImageData = anAlphaReader->GetOutput(); + + int* aMainImageSize = aMainImageData->GetDimensions(); + int* anAlphaImageSize = anAlphaImageData->GetDimensions(); + if(aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1]) + throw std::runtime_error("GaussPoints_i::MakeTexture : aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1]"); + + int aNbCompositeComponents = 4; + vtkImageData* aCompositeImageData = vtkImageData::New(); + aCompositeImageData->SetDimensions(aMainImageSize); + aCompositeImageData->SetScalarTypeToUnsignedChar(); + aCompositeImageData->SetNumberOfScalarComponents(aNbCompositeComponents); + aCompositeImageData->AllocateScalars(); + + unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer(); + unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer(); + unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer(); - cout << "--------------------" << endl; - cout << "--------DATA--------" << endl; - cout << "--------------------" << endl; - */ - for( int i = 0; i < xSize * ySize * 4; i += 4 ) + int aCompositeSize = aMainImageSize[0] * aMainImageSize[1]; + int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents(); + int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents(); + + int aMainId = 0, anAlphaId = 0, aCompositeId = 0; + for(; aCompositeId < aCompositeSize;) { - dataPtr[ i ] = dataPtr2[ i / 4 * N2 ]; - dataPtr[i+1] = dataPtr2[ i / 4 * N2 + 1 ]; - dataPtr[i+2] = dataPtr2[ i / 4 * N2 + 2 ]; - dataPtr[i+3] = dataPtr1[ i / 4 * N1 ]; - /* - cout << i / 4 << " " << (int)dataPtr[ i ] << " " << (int)dataPtr[i+1] << - " " << (int)dataPtr[i+2] << " " << (int)dataPtr[i+3] << endl; - if( !( (i/4+1) % xSize ) ) - cout << "--------------------" << endl; - */ + aCompositeDataPtr[aCompositeId] = aMainDataPtr[aMainId]; + aCompositeDataPtr[aCompositeId + 1] = aMainDataPtr[aMainId + 1]; + aCompositeDataPtr[aCompositeId + 2] = aMainDataPtr[aMainId + 2]; + aCompositeDataPtr[aCompositeId + 3] = anAlphaDataPtr[anAlphaId]; + + aMainId += aNbMainComponents; + anAlphaId += aNbAlphaComponents; + aCompositeId += aNbCompositeComponents; } - imageData->Update(); - //imageData->Print( cout ); + aMainReader->Delete(); + anAlphaReader->Delete(); + aCompositeImageData->Update(); - myGaussPointsPL->SetImageData( imageData ); + myGaussPointsPL->SetImageData(aCompositeImageData); } diff --git a/src/VISU_I/VISU_Mesh_i.cc b/src/VISU_I/VISU_Mesh_i.cc index 41c0fdfc..fd62cdc1 100644 --- a/src/VISU_I/VISU_Mesh_i.cc +++ b/src/VISU_I/VISU_Mesh_i.cc @@ -75,7 +75,7 @@ Mesh_i(Result_i* theResult, void VISU::Mesh_i::RemoveFromStudy() { - VISU::DeleteActors(this); + VISU::Prs3d_i::RemoveFromStudy(); VISU::RemoveFromStudy(mySObject); } diff --git a/src/VISU_I/VISU_Prs3d_i.cc b/src/VISU_I/VISU_Prs3d_i.cc index 14bfe1ab..4ef9bfde 100644 --- a/src/VISU_I/VISU_Prs3d_i.cc +++ b/src/VISU_I/VISU_Prs3d_i.cc @@ -30,8 +30,9 @@ #include "VISU_Result_i.hh" #include "VISU_Actor.h" -#include -#include +#include +#include + #include @@ -39,7 +40,7 @@ using namespace VISU; using namespace std; #ifdef _DEBUG_ -static int MYDEBUG = 1; +static int MYDEBUG = 0; #else static int MYDEBUG = 0; #endif @@ -50,12 +51,15 @@ VISU::Prs3d_i ::Prs3d_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) : PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), mySObject(SALOMEDS::SObject::_duplicate(theSObject)), + myActorCollection(vtkActorCollection::New()), + myResult(theResult), myAddToStudy(true), myPipeLine(NULL) { + if(MYDEBUG) MESSAGE("Prs3d_i() - this = "<Delete(); myResult->Register(); } @@ -63,12 +67,15 @@ VISU::Prs3d_i ::Prs3d_i(Result_i* theResult, bool theAddToStudy) : PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), + myActorCollection(vtkActorCollection::New()), mySObject(SALOMEDS::SObject::_nil()), myAddToStudy(theAddToStudy), + myResult(theResult), myPipeLine(NULL) { + if(MYDEBUG) MESSAGE("Prs3d_i() - this = "<Delete(); myResult->Register(); } @@ -85,8 +92,7 @@ VISU::Prs3d_i VISU::Prs3d_i ::~Prs3d_i() { - if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<setIO(anIO); } - theActor->SetFactory(this); - myUpdateActorsSignal.connect(boost::bind(&VISU_Actor::Update,theActor)); - theActor->SetPipeLine(GetPipeLine()); + Update(); theActor->SetPrs3d(this); theActor->SetPosition(myOffset); + theActor->SetPipeLine(GetPipeLine()); + + theActor->SetFactory(this); + myUpdateActorsSignal.connect(boost::bind(&VISU_Actor::Update,theActor)); + myRemoveActorsFromRendererSignal.connect(boost::bind(&VISU_Actor::RemoveFromRender,theActor)); + + myActorCollection->AddItem(theActor); + theActor->Delete(); + }catch(std::bad_alloc& ex){ throw std::runtime_error("CreateActor >> No enough memory"); throw ex; @@ -210,7 +232,7 @@ void VISU::Prs3d_i ::UpdateActor(VISU_Actor* theActor) { - if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor - this = "< #include +#include class VISU_PipeLine; class VISU_Actor; class vtkPlane; +class vtkActorCollection; class vtkUnstructuredGrid; namespace VISU @@ -92,26 +93,6 @@ namespace VISU ToStream(std::ostringstream& theStr); //---------------------------------------------------------------------------- - protected: - bool myAddToStudy; - float myOffset[3]; - Result_i *myResult; - VISU_PipeLine *myPipeLine; - SALOMEDS::SObject_var mySObject; - std::string myMeshName; - - boost::signal0 myUpdateActorsSignal; - - void - CreateActor(VISU_Actor* theActor, - const Handle(SALOME_InteractiveObject)& theIO = NULL); - - virtual - VISU_PipeLine* - GetPipeLine(); - - public: - //---------------------------------------------------------------------------- Result_i* GetResult() const; @@ -127,6 +108,11 @@ namespace VISU void Update(); + virtual + void + RemoveFromStudy(); + + //---------------------------------------------------------------------------- VISU_PipeLine* GetPL(); @@ -180,12 +166,35 @@ namespace VISU virtual void GetOffset(float& theDx, float& theDy, float& theDz); + + //---------------------------------------------------------------------------- + protected: + void + CreateActor(VISU_Actor* theActor, + const Handle(SALOME_InteractiveObject)& theIO = NULL); + + virtual + VISU_PipeLine* + GetPipeLine(); + + bool myAddToStudy; + float myOffset[3]; + Result_i *myResult; + VISU_PipeLine *myPipeLine; + SALOMEDS::SObject_var mySObject; + std::string myMeshName; + + boost::signal0 myUpdateActorsSignal; + boost::signal0 myRemoveActorsFromRendererSignal; + vtkSmartPointer myActorCollection; + }; //---------------------------------------------------------------------------- Result_i* GetResult(SALOMEDS::SObject_ptr theSObject); + //---------------------------------------------------------------------------- template Storable* Restore(SALOMEDS::SObject_ptr theSObject, @@ -199,6 +208,7 @@ namespace VISU } return NULL; } + //---------------------------------------------------------------------------- } #endif diff --git a/src/VISU_I/VISU_ScalarMap_i.cc b/src/VISU_I/VISU_ScalarMap_i.cc index d3e2fbbe..5fcedadf 100644 --- a/src/VISU_I/VISU_ScalarMap_i.cc +++ b/src/VISU_I/VISU_ScalarMap_i.cc @@ -96,7 +96,7 @@ ScalarMap_i(Result_i* theResult, void VISU::ScalarMap_i::RemoveFromStudy() { - VISU::DeleteActors(this); + VISU::Prs3d_i::RemoveFromStudy(); VISU::RemoveFromStudy(mySObject,false); } -- 2.39.2