#include "VISU_GaussPtsAct.h"
#include "VISU_GaussPointsPL.hxx"
-
#include "VISU_OpenGLPointSpriteMapper.hxx"
+#include <vtkImageData.h>
+#include <vtkXMLImageDataReader.h>
+
using namespace VISU;
using namespace std;
static int MYDEBUG = 0;
#endif
-#include <vtkImageData.h>
-#include <vtkXMLImageDataReader.h>
-
//----------------------------------------------------------------------------
int
VISU::GaussPoints_i
myIsColored(true),
myColor(Qt::blue)
{
- if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i");
+ if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<<this);
}
ScalarMap_i(theResult,theSObject),
myGaussPointsPL(NULL)
{
- if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i");
+ if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<<this);
}
VISU::GaussPoints_i
::~GaussPoints_i()
{
- if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i()");
+ if(MYDEBUG) MESSAGE("GaussPoints_i::~GaussPoints_i() - this = "<<this);
}
myColor.blue() / 255.0);
}
VISU::ScalarMap_i::UpdateActor(theActor);
- ((VISU_GaussPtsAct*)theActor)->GetPSMapper()->ShallowCopy( myPipeLine->GetMapper() );
theActor->GetPipeLine()->ShallowCopy(myPipeLine);
}
}
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);
}
#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>
using namespace std;
#ifdef _DEBUG_
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
#else
static int MYDEBUG = 0;
#endif
::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();
}
::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();
}
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();
}
}
}
+void
+VISU::Prs3d_i
+::RemoveFromStudy()
+{
+ myRemoveActorsFromRendererSignal();
+ myActorCollection->RemoveAllItems();
+}
+
+
+//----------------------------------------------------------------------------
VISU_PipeLine*
VISU::Prs3d_i
::GetPipeLine()
::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;
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();
#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
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;
void
Update();
+ virtual
+ void
+ RemoveFromStudy();
+
+ //----------------------------------------------------------------------------
VISU_PipeLine*
GetPL();
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,
}
return NULL;
}
+ //----------------------------------------------------------------------------
}
#endif