From: ouv Date: Thu, 22 Sep 2005 13:01:35 +0000 (+0000) Subject: Texture for Point Sprites X-Git-Tag: BR-D5-38-2003_D2005-12-10~158 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f1414d0fa259a675efade217ae91958f4a0e426b;p=modules%2Fvisu.git Texture for Point Sprites --- diff --git a/src/PIPELINE/VISU_GaussPointsPL.cxx b/src/PIPELINE/VISU_GaussPointsPL.cxx index 57e4f1e3..c335a520 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.cxx +++ b/src/PIPELINE/VISU_GaussPointsPL.cxx @@ -36,6 +36,7 @@ #include #include #include +#include //---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_GaussPointsPL); @@ -209,7 +210,6 @@ void VISU_GaussPointsPL ::SetClamp(float theClamp) { - //cout << "VISU_GaussPointsPL::SetClamp " << theClamp << endl;; myPSMapper->SetPointSpriteClamp( theClamp ); Modified(); @@ -352,3 +352,13 @@ VISU_GaussPointsPL return myAverageCellSize*myRelativeMaxSize; } +//---------------------------------------------------------------------------- +void +VISU_GaussPointsPL +::SetImageData(vtkImageData* theImageData) +{ + //cout << "VISU_GaussPointsPL::SetImageData " << theImageData << endl; + //theImageData->Print( cout ); + + myPSMapper->SetImageData( theImageData ); +} diff --git a/src/PIPELINE/VISU_GaussPointsPL.hxx b/src/PIPELINE/VISU_GaussPointsPL.hxx index da44167a..f559016d 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.hxx +++ b/src/PIPELINE/VISU_GaussPointsPL.hxx @@ -35,6 +35,7 @@ class VISU_OpenGLPointSpriteMapper; class vtkGeometryFilter; class vtkDataArray; +class vtkImageData; class VISU_GaussPointsPL : public VISU_ScalarMapPL { @@ -146,6 +147,9 @@ public: float GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray); + void + SetImageData(vtkImageData* theImageData); + protected: VISU_OpenGLPointSpriteMapper* myPSMapper; vtkGeometryFilter* myGeomFilter; diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 7912a6bb..c4e69e35 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -125,12 +125,15 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() this->OpenGLLibrary = 0; #endif + this->AlphaThreshold = 0.1; + this->PointSpriteClamp = 100.0; this->PointSpriteSize = 0.0; this->PointSpriteMinSize = 15.0; this->PointSpriteMaxSize = 50.0; this->PointSpriteMagnification = 1.0; + this->ImageData = 0; this->XMLImageDataReader = vtkXMLImageDataReader::New(); this->PointSpriteTexture = 0; this->IsUsingOpenGLMapper = false; @@ -154,6 +157,11 @@ VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper() delete [] this->SizeChannelArray; this->SizeChannelArray = NULL; } + if (this->ImageData) + { + this->ImageData->Delete(); + this->ImageData = NULL; + } if (this->XMLImageDataReader) { this->XMLImageDataReader->Delete(); @@ -171,6 +179,8 @@ void VISU_OpenGLPointSpriteMapper::ShallowCopy( vtkAbstractMapper* mapper ) this->SetPointSpriteMinSize( m->GetPointSpriteMinSize() ); this->SetPointSpriteMaxSize( m->GetPointSpriteMaxSize() ); this->SetPointSpriteMagnification( m->GetPointSpriteMagnification() ); + + this->SetImageData( m->GetImageData() ); } MAPPER_SUPERCLASS::ShallowCopy(mapper); @@ -672,6 +682,7 @@ void VISU_OpenGLPointSpriteMapper::InitSprites() glDisable(GL_DEPTH_TEST); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); + glAlphaFunc( GL_GREATER, this->AlphaThreshold ); break; } @@ -730,20 +741,23 @@ void VISU_OpenGLPointSpriteMapper::CleanupSprites() //glDisable( GL_VERTEX_PROGRAM_ARB ); } //----------------------------------------------------------------------------- -void VISU_OpenGLPointSpriteMapper::InitTexture( vtkImageData* imageData ) +void VISU_OpenGLPointSpriteMapper::SetImageData( vtkImageData* theImageData ) +{ + //cout << "VISU_OpenGLPointSpriteMapper::SetImageData " << this << " " << theImageData << endl; + //theImageData->Print( cout ); + + this->ImageData = theImageData; + + //cout << this->ImageData << endl; +} +//----------------------------------------------------------------------------- +void VISU_OpenGLPointSpriteMapper::InitTexture() { - //cout << "VISU_OpenGLPointSpriteMapper::InitTexture" << endl; + //cout << "VISU_OpenGLPointSpriteMapper::InitTexture " << this << " " << this->ImageData << endl; - //imageData->DebugOn(); - imageData->RequestExactExtentOn(); - imageData->UpdateInformation(); - imageData->SetUpdateExtentToWholeExtent(); - imageData->Update(); - //cout << "Dimension of image data : " << imageData->GetDataDimension() << endl; + //this->ImageData->Print( cout ); - int* size = imageData->GetDimensions(); - vtkDataArray* scalars = imageData->GetPointData()->GetScalars(); - unsigned char* dataPtr = static_cast(scalars)->GetPointer(0); + unsigned char* dataPtr = (unsigned char*)this->ImageData->GetScalarPointer(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); @@ -753,7 +767,7 @@ void VISU_OpenGLPointSpriteMapper::InitTexture( vtkImageData* imageData ) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, - GL_RGBA, GL_UNSIGNED_BYTE, dataPtr); + GL_RGBA, GL_UNSIGNED_BYTE, dataPtr ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_TEXTURE_2D ); @@ -773,11 +787,13 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, vtkCellArray *cells, vtkRenderer *ren) { - this->XMLImageDataReader->SetFileName( "/dn06/salome/ouv/SALOME/TextureAlphaChannel.vti" ); - vtkImageData* imageData = this->XMLImageDataReader->GetOutput(); - this->InitTexture( imageData ); + //this->XMLImageDataReader->SetFileName( "/dn06/salome/ouv/SALOME/TextureAlphaChannel.vti" ); + //vtkImageData* imageData = this->XMLImageDataReader->GetOutput(); + + if( this->ImageData ) + this->InitTexture(); - InitSprites(); + this->InitSprites(); glPointSize( this->DefaultPointSize ); diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx index d2086b11..45a96bb1 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -134,7 +134,7 @@ public: // Description: // Initializing texture for Point Sprites - void InitTexture( vtkImageData* ); + void InitTexture(); // Description: // Return the maximum point size supported by the graphics hardware. @@ -154,6 +154,10 @@ public: void SetPointSpriteMaxSize( float ); void SetPointSpriteMagnification( float ); + void SetImageData( vtkImageData* ); + //vtkSetMacro(ImageData, vtkImageData*); + vtkGetMacro(ImageData, vtkImageData*); + protected: VISU_OpenGLPointSpriteMapper(); ~VISU_OpenGLPointSpriteMapper(); @@ -193,6 +197,8 @@ protected: void* OpenGLLibrary; #endif + float AlphaThreshold; + float PointSpriteClamp; float PointSpriteSize; float PointSpriteMinSize; @@ -202,6 +208,8 @@ protected: vtkXMLImageDataReader* XMLImageDataReader; GLuint PointSpriteTexture; + vtkImageData* ImageData; + bool IsUsingOpenGLMapper; }; diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx index 3344117b..f4ff3629 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx @@ -24,7 +24,6 @@ // File : VisuGUI_MagnitudeDlg.cxx // Author : Laurent CORNABE & Hubert ROLLAND // Module : VISU -// $Header$ #include "VisuGUI_GaussPointsDlg.h" @@ -962,6 +961,9 @@ void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::GaussPoints_i* thePrs ) myMagnificationSpinBox->setValue( thePrs->GetGaussPointsPL()->GetMagnification() * 100.0 ); myIncrementSpinBox->setValue( thePrs->GetGaussPointsPL()->GetMagnificationIncrement() * 100.0 ); + myMainTextureLineEdit->setText( thePrs->GetMainTexture().section( '/', -1 ) ); + myAlphaChannelTextureLineEdit->setText( thePrs->GetAlphaChannelTexture().section( '/', -1 ) ); + myScalarPane->initFromPrsObject(thePrs); } @@ -985,29 +987,70 @@ int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::GaussPoints_i* thePrs ) thePrs->GetGaussPointsPL()->SetMagnification( myMagnificationSpinBox->value() / 100.0 ); thePrs->GetGaussPointsPL()->SetMagnificationIncrement( myIncrementSpinBox->value() / 100.0 ); - return myScalarPane->storeToPrsObject(thePrs); + myScalarPane->storeToPrsObject(thePrs); + + // Texture + if( myMainTexture.isNull() || myAlphaChannelTexture.isNull() ) + { + //return 1; + myMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp"; + myAlphaChannelTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp"; + } + + QString mainTextureImage = myMainTexture; + QString mainTextureFormat = mainTextureImage.section( '.', -1 ); + QString mainTextureVTI = mainTextureImage.section( '.', 0, -2 ) + ".vti"; + + QString command1 = QString( "VISU_img2vti " ) + mainTextureFormat + " " + mainTextureImage + " " + mainTextureVTI; + cout << command1.latin1() << endl; + system( command1.latin1() ); + + QString alphaTextureImage = myAlphaChannelTexture; + QString alphaTextureFormat = alphaTextureImage.section( '.', -1 ); + QString alphaTextureVTI = alphaTextureImage.section( '.', 0, -2 ) + ".vti"; + + QString command2 = QString( "VISU_img2vti " ) + alphaTextureFormat + " " + alphaTextureImage + " " + alphaTextureVTI; + cout << command2.latin1() << endl; + system( command2.latin1() ); + + cout << mainTextureVTI.latin1() << endl; + cout << alphaTextureVTI.latin1() << endl; + + thePrs->SetMainTexture( mainTextureImage ); + thePrs->SetAlphaChannelTexture( alphaTextureImage ); + thePrs->MakeTexture( mainTextureVTI, alphaTextureVTI ); + + return 1; } void VisuGUI_GaussPointsDlg::accept() { //if( myScalarPane->check() ) - QDialog::accept(); + QDialog::accept(); } void VisuGUI_GaussPointsDlg::onBrowseMainTexture() { - QString aFileName = QFileDialog::getOpenFileName( QString::null, "Bitmap (*.jpg *.gif *.png)", this ); + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/"; + QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this ); + + if( aFileName.isNull() ) + return; - if( !aFileName.isNull() ) - myMainTextureLineEdit->setText( aFileName ); + myMainTexture = aFileName; + myMainTextureLineEdit->setText( aFileName.section( '/', -1 ) ); } void VisuGUI_GaussPointsDlg::onBrowseAlphaChannelTexture() { - QString aFileName = QFileDialog::getOpenFileName( QString::null, "Bitmap (*.jpg *.gif *.png)", this ); + QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/"; + QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this ); + + if( aFileName.isNull() ) + return; - if( !aFileName.isNull() ) - myAlphaChannelTextureLineEdit->setText( aFileName ); + myAlphaChannelTexture = aFileName; + myAlphaChannelTextureLineEdit->setText( aFileName.section( '/', -1 ) ); } void VisuGUI_GaussPointsDlg::onColorButtonPressed() diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.h b/src/VISUGUI/VisuGUI_GaussPointsDlg.h index fdcda88c..b15310b0 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.h +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.h @@ -137,6 +137,9 @@ protected slots: private: VisuGUI_GaussScalarBarPane* myScalarPane; + QString myMainTexture; + QString myAlphaChannelTexture; + QtxDblSpinBox* myClampSpinBox; QLineEdit* myMainTextureLineEdit; diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index 0e8e12e6..ff778906 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -31,6 +31,8 @@ #include "VISU_GaussPointsPL.hxx" +#include "VISU_OpenGLPointSpriteMapper.hxx" + using namespace VISU; using namespace std; @@ -40,6 +42,9 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif +#include +#include + //---------------------------------------------------------------------------- int VISU::GaussPoints_i @@ -284,6 +289,8 @@ VISU::GaussPoints_i myColor.blue() / 255.0); } VISU::ScalarMap_i::UpdateActor(theActor); + ((VISU_GaussPtsAct*)theActor)->GetPSMapper()->ShallowCopy( myPipeLine->GetMapper() ); + theActor->GetPipeLine()->ShallowCopy(myPipeLine); } } @@ -297,3 +304,80 @@ VISU::GaussPoints_i myGaussPointsPL->ChangeMagnification(aChangeMagnification); UpdateActors(); } + +void +VISU::GaussPoints_i +::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; + } + + 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; + } + + cout << "--------------------" << endl; + cout << "--------DATA--------" << endl; + cout << "--------------------" << endl; + */ + for( int i = 0; i < xSize * ySize * 4; i += 4 ) + { + 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; + */ + } + imageData->Update(); + //imageData->Print( cout ); + + myGaussPointsPL->SetImageData( imageData ); +} diff --git a/src/VISU_I/VISU_GaussPoints_i.hh b/src/VISU_I/VISU_GaussPoints_i.hh index becaaada..916c1f95 100644 --- a/src/VISU_I/VISU_GaussPoints_i.hh +++ b/src/VISU_I/VISU_GaussPoints_i.hh @@ -70,6 +70,21 @@ namespace VISU void ShowColored( bool theColored ); + void SetMainTexture( const QString& theMainTexture ) { + myMainTexture = theMainTexture; + } + + QString GetMainTexture() { return myMainTexture; } + + void SetAlphaChannelTexture( const QString& theAlphaChannelTexture ) { + myAlphaChannelTexture = theAlphaChannelTexture; + } + + QString GetAlphaChannelTexture() { return myAlphaChannelTexture; } + + void MakeTexture( const QString& theMainTexture, + const QString& theAlphaChannelTexture ); + protected: virtual void @@ -84,9 +99,13 @@ namespace VISU GetPipeLine(); VISU_GaussPointsPL *myGaussPointsPL; + bool myIsColored; QColor myColor; + QString myMainTexture; + QString myAlphaChannelTexture; + public: static int