#include <vtkImageGaussianSource.h>
#include <vtkXMLImageDataReader.h>
#include <vtkGeometryFilter.h>
+#include <vtkImageData.h>
//----------------------------------------------------------------------------
vtkStandardNewMacro(VISU_GaussPointsPL);
VISU_GaussPointsPL
::SetClamp(float theClamp)
{
- //cout << "VISU_GaussPointsPL::SetClamp " << theClamp << endl;;
myPSMapper->SetPointSpriteClamp( theClamp );
Modified();
return myAverageCellSize*myRelativeMaxSize;
}
+//----------------------------------------------------------------------------
+void
+VISU_GaussPointsPL
+::SetImageData(vtkImageData* theImageData)
+{
+ //cout << "VISU_GaussPointsPL::SetImageData " << theImageData << endl;
+ //theImageData->Print( cout );
+
+ myPSMapper->SetImageData( theImageData );
+}
class vtkGeometryFilter;
class vtkDataArray;
+class vtkImageData;
class VISU_GaussPointsPL : public VISU_ScalarMapPL
{
float
GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray);
+ void
+ SetImageData(vtkImageData* theImageData);
+
protected:
VISU_OpenGLPointSpriteMapper* myPSMapper;
vtkGeometryFilter* myGeomFilter;
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;
delete [] this->SizeChannelArray;
this->SizeChannelArray = NULL;
}
+ if (this->ImageData)
+ {
+ this->ImageData->Delete();
+ this->ImageData = NULL;
+ }
if (this->XMLImageDataReader)
{
this->XMLImageDataReader->Delete();
this->SetPointSpriteMinSize( m->GetPointSpriteMinSize() );
this->SetPointSpriteMaxSize( m->GetPointSpriteMaxSize() );
this->SetPointSpriteMagnification( m->GetPointSpriteMagnification() );
+
+ this->SetImageData( m->GetImageData() );
}
MAPPER_SUPERCLASS::ShallowCopy(mapper);
glDisable(GL_DEPTH_TEST);
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
+ glAlphaFunc( GL_GREATER, this->AlphaThreshold );
break;
}
//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<vtkUnsignedCharArray*>(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 );
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 );
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 );
// Description:
// Initializing texture for Point Sprites
- void InitTexture( vtkImageData* );
+ void InitTexture();
// Description:
// Return the maximum point size supported by the graphics hardware.
void SetPointSpriteMaxSize( float );
void SetPointSpriteMagnification( float );
+ void SetImageData( vtkImageData* );
+ //vtkSetMacro(ImageData, vtkImageData*);
+ vtkGetMacro(ImageData, vtkImageData*);
+
protected:
VISU_OpenGLPointSpriteMapper();
~VISU_OpenGLPointSpriteMapper();
void* OpenGLLibrary;
#endif
+ float AlphaThreshold;
+
float PointSpriteClamp;
float PointSpriteSize;
float PointSpriteMinSize;
vtkXMLImageDataReader* XMLImageDataReader;
GLuint PointSpriteTexture;
+ vtkImageData* ImageData;
+
bool IsUsingOpenGLMapper;
};
// File : VisuGUI_MagnitudeDlg.cxx
// Author : Laurent CORNABE & Hubert ROLLAND
// Module : VISU
-// $Header$
#include "VisuGUI_GaussPointsDlg.h"
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);
}
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()
private:
VisuGUI_GaussScalarBarPane* myScalarPane;
+ QString myMainTexture;
+ QString myAlphaChannelTexture;
+
QtxDblSpinBox* myClampSpinBox;
QLineEdit* myMainTextureLineEdit;
#include "VISU_GaussPointsPL.hxx"
+#include "VISU_OpenGLPointSpriteMapper.hxx"
+
using namespace VISU;
using namespace std;
static int MYDEBUG = 0;
#endif
+#include <vtkImageData.h>
+#include <vtkXMLImageDataReader.h>
+
//----------------------------------------------------------------------------
int
VISU::GaussPoints_i
myColor.blue() / 255.0);
}
VISU::ScalarMap_i::UpdateActor(theActor);
+ ((VISU_GaussPtsAct*)theActor)->GetPSMapper()->ShallowCopy( myPipeLine->GetMapper() );
+ theActor->GetPipeLine()->ShallowCopy(myPipeLine);
}
}
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 );
+}
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
GetPipeLine();
VISU_GaussPointsPL *myGaussPointsPL;
+
bool myIsColored;
QColor myColor;
+ QString myMainTexture;
+ QString myAlphaChannelTexture;
+
public:
static
int