]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To implement automatic Actors destruction by connection VISU_Actor::RemoveFromRendere...
authorapo <apo@opencascade.com>
Fri, 23 Sep 2005 05:53:06 +0000 (05:53 +0000)
committerapo <apo@opencascade.com>
Fri, 23 Sep 2005 05:53:06 +0000 (05:53 +0000)
src/VISU_I/VISU_GaussPoints_i.cc
src/VISU_I/VISU_Mesh_i.cc
src/VISU_I/VISU_Prs3d_i.cc
src/VISU_I/VISU_Prs3d_i.hh
src/VISU_I/VISU_ScalarMap_i.cc

index ff7789064958f2e94f5139bf2ae78ef0c6c09db7..c15f49d6d568bd4b6fa9f3d01a4cc5f3a3f05529 100644 (file)
 #include "VISU_GaussPtsAct.h"
 #include "VISU_GaussPointsPL.hxx"
 
-
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 
+#include <vtkImageData.h>
+#include <vtkXMLImageDataReader.h>
+
 using namespace VISU;
 using namespace std;
 
@@ -42,9 +44,6 @@ static int MYDEBUG = 1;
 static int MYDEBUG = 0;
 #endif
 
-#include <vtkImageData.h>
-#include <vtkXMLImageDataReader.h>
-
 //----------------------------------------------------------------------------
 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 = "<<this);
 }
 
 
@@ -113,7 +112,7 @@ GaussPoints_i(Result_i* theResult,
   ScalarMap_i(theResult,theSObject),
   myGaussPointsPL(NULL)
 {
-  if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i");
+  if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<<this);
 }
 
 
@@ -149,7 +148,7 @@ VISU::GaussPoints_i
 VISU::GaussPoints_i
 ::~GaussPoints_i()
 {
-  if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i()");
+  if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i() - this = "<<this);
 }
 
 
@@ -289,7 +288,6 @@ VISU::GaussPoints_i
                                       myColor.blue() / 255.0);
     }
     VISU::ScalarMap_i::UpdateActor(theActor);
-    ((VISU_GaussPtsAct*)theActor)->GetPSMapper()->ShallowCopy( myPipeLine->GetMapper() );
     theActor->GetPipeLine()->ShallowCopy(myPipeLine);
   }
 }
@@ -307,77 +305,59 @@ VISU::GaussPoints_i
 
 void
 VISU::GaussPoints_i
-::MakeTexture( const QString& theMainTexture, const QString& theAlphaChannelTexture )
+::MakeTexture( const QString& theMainTexture, 
+              const QString& theAlphaChannelTexture )
 {
   if( theMainTexture.isNull() || theAlphaChannelTexture.isNull() )
     return;
 
-  vtkXMLImageDataReader* aReader1 = vtkXMLImageDataReader::New();
-  vtkXMLImageDataReader* aReader2 = vtkXMLImageDataReader::New();
-
-  aReader1->SetFileName( theMainTexture );
-  aReader2->SetFileName( theAlphaChannelTexture );
-
-  aReader1->Update();
-  aReader2->Update();
-
-  vtkImageData* imageData1 = aReader1->GetOutput();
-  vtkImageData* imageData2 = aReader2->GetOutput();
-
-  unsigned char* dataPtr1 = (unsigned char*)imageData1->GetScalarPointer();
-  unsigned char* dataPtr2 = (unsigned char*)imageData2->GetScalarPointer();
-
-  int xSize = 16;
-  int ySize = 16;
-  int N1 = imageData1->GetNumberOfScalarComponents();
-  int N2 = imageData2->GetNumberOfScalarComponents();
-
-  vtkImageData* imageData = vtkImageData::New();
-  imageData->SetDimensions(xSize, ySize, 1);
-  imageData->SetScalarTypeToUnsignedChar();        
-  imageData->SetNumberOfScalarComponents(4);
-  imageData->AllocateScalars();
-  unsigned char *dataPtr = (unsigned char * )imageData->GetScalarPointer();
-  /*
-  cout << "--------------------" << endl;
-  cout << "--------DATA1-------" << endl;
-  cout << "--------------------" << endl;
-  for( int i = 0; i < xSize*ySize*N1; i += N1 )
-  {
-    cout << i / N1 << " " << (int)dataPtr1[ i ] << " " << (int)dataPtr1[i+1] << " " << (int)dataPtr1[i+2] << endl;
-    if( !( (i/N1+1) % xSize ) )
-      cout << "--------------------" << endl;
-  }
+  vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New();
+  vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New();
 
-  cout << "--------------------" << endl;
-  cout << "--------DATA2-------" << endl;
-  cout << "--------------------" << endl;
-  for( int i = 0; i < xSize*ySize*N2; i += N2 )
-  {
-    cout << i / N2 << " " << (int)dataPtr2[ i ] << " " << (int)dataPtr2[i+1] << " " << (int)dataPtr2[i+2] << endl;
-    if( !( (i/N2+1) % xSize ) )
-      cout << "--------------------" << endl;
-  }
+  aMainReader->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);
 }
index 41c0fdfc8f40939d4a1bb3fa1df0dc0b103ecb89..fd62cdc115d7252b36c8c362c77f0d9c534533f1 100644 (file)
@@ -75,7 +75,7 @@ Mesh_i(Result_i* theResult,
 
 void VISU::Mesh_i::RemoveFromStudy()
 {
-  VISU::DeleteActors(this);
+  VISU::Prs3d_i::RemoveFromStudy();
   VISU::RemoveFromStudy(mySObject);
 }
 
index 14bfe1ab23124974e28925ba3df561021ede52e6..4ef9bfdee1fc26d0ad8ac7630770c5e9384b07f5 100644 (file)
@@ -30,8 +30,9 @@
 #include "VISU_Result_i.hh"
 #include "VISU_Actor.h"
 
-#include <vtkGeometryFilter.h>
-#include <vtkDataSetMapper.h>
+#include <vtkActorCollection.h>
+#include <vtkMapper.h>
+
 
 #include <boost/bind.hpp>
 
@@ -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 = "<<this);
   myOffset[0] = myOffset[1] = myOffset[2] = 0;
+  myActorCollection->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 = "<<this);
   myOffset[0] = myOffset[1] = myOffset[2] = 0;
+  myActorCollection->Delete();
   myResult->Register();
 }
 
@@ -85,8 +92,7 @@ VISU::Prs3d_i
 VISU::Prs3d_i
 ::~Prs3d_i() 
 {
-  if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this
-                     <<"; GetReferenceCount() = "<<myPipeLine->GetReferenceCount());
+  if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this);
   myPipeLine->Delete();
   myResult->Destroy();
 }
@@ -156,6 +162,16 @@ VISU::Prs3d_i
   }
 }
 
+void
+VISU::Prs3d_i
+::RemoveFromStudy() 
+{
+  myRemoveActorsFromRendererSignal();
+  myActorCollection->RemoveAllItems();
+}
+
+
+//----------------------------------------------------------------------------
 VISU_PipeLine* 
 VISU::Prs3d_i
 ::GetPipeLine()
@@ -184,18 +200,24 @@ VISU::Prs3d_i
 ::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
 {
   try{
-    Update();
     Handle(SALOME_InteractiveObject) anIO = theIO;
     if(anIO.IsNull() && (!mySObject->_is_nil())){
       anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
       theActor->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 = "<<this);
+  if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor - this = "<<this<<"; theActor = "<<theActor);
   theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper());
   theActor->SetPosition(myOffset);
   theActor->Modified();
index 8d5b88e906f46f099b6de779b55673925a07ccff..5d560d70d75b0c76473a13f475e2433eef7e555a 100644 (file)
 #include "SALOME_GenericObj_i.hh"
 #include "SALOME_InteractiveObject.hxx"
 
-#include <vtkPlaneSource.h>
 #include <boost/signals/signal0.hpp>
+#include <vtkSmartPointer.h>
 
 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<void> 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<void> myUpdateActorsSignal;
+    boost::signal0<void> myRemoveActorsFromRendererSignal;
+    vtkSmartPointer<vtkActorCollection> myActorCollection;
+
   };
 
   //----------------------------------------------------------------------------
   Result_i* 
   GetResult(SALOMEDS::SObject_ptr theSObject);
 
+  //----------------------------------------------------------------------------
   template<class TPrs3d>
   Storable* 
   Restore(SALOMEDS::SObject_ptr theSObject,
@@ -199,6 +208,7 @@ namespace VISU
     }
     return NULL;
   }
+  //----------------------------------------------------------------------------
 }
 
 #endif
index d3e2fbbe8c936555c12f8a6dd24a9bc25220b7a5..5fcedadfd8ee0faf937f641102eecc8d69b8a56d 100644 (file)
@@ -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);
 }