From: rnv Date: Fri, 13 Sep 2013 09:49:43 +0000 (+0000) Subject: Implementation of the "0022102: EDF 1496 SMESH : Displaying of discrete elements... X-Git-Tag: BR_hydro_v_0_3_1~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dd243976e72b27995de19643a438035581c25947;p=modules%2Fgui.git Implementation of the "0022102: EDF 1496 SMESH : Displaying of discrete elements in SMESH relating to their attribute (diameter)" issue. --- diff --git a/adm_local/cmake_files/FindSalomeVTK.cmake b/adm_local/cmake_files/FindSalomeVTK.cmake index 4338253bd..b26e15460 100644 --- a/adm_local/cmake_files/FindSalomeVTK.cmake +++ b/adm_local/cmake_files/FindSalomeVTK.cmake @@ -35,6 +35,7 @@ SET(SalomeVTK_FIND_COMPONENTS vtkIOExport #vtkWrappingPythonCore ## ParaView 4.0.1 vtkWrappingPython + vtkIOXML ) # If no VTK root dir is specified, try the ParaView root dir: diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx index bdc94594b..8c122260e 100644 --- a/src/SVTK/SVTK_DeviceActor.cxx +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -696,6 +696,14 @@ double SVTK_DeviceActor::GetQuadraticArcAngle(){ return myGeomFilter->GetQuadraticArcAngle(); } +/*! + * Set ball drawing enabled + * \param theBallEnabled flag to enable/disable balls + */ +void SVTK_DeviceActor::SetBallEnabled( bool theBallEnabled ) { + myMapper->SetBallEnabled( theBallEnabled ); +} + /*! * Set point marker enabled * \param theMarkerEnabled flag to enable/disable point marker diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h index 72187885f..ac0ff4009 100644 --- a/src/SVTK/SVTK_DeviceActor.h +++ b/src/SVTK/SVTK_DeviceActor.h @@ -214,6 +214,10 @@ class SVTK_EXPORT SVTK_DeviceActor: public vtkLODActor SetShaded(bool theShaded); //@} + /** @name For ball marker management purpose */ + void + SetBallEnabled( bool ); + /** @name For marker management purpose */ void SetMarkerEnabled( bool ); diff --git a/src/VTKViewer/CMakeLists.txt b/src/VTKViewer/CMakeLists.txt index 39b1d8d31..66bd40199 100755 --- a/src/VTKViewer/CMakeLists.txt +++ b/src/VTKViewer/CMakeLists.txt @@ -179,3 +179,14 @@ INSTALL(FILES ${VTKViewer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) QT4_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}") INSTALL(FILES ${_other_RESOURCES} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) +FILE(GLOB GUIPNG_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.png") +INSTALL(FILES ${GUIPNG_DATA} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) + +FILE(GLOB GUIVTI_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.vti") +INSTALL(FILES ${GUIVTI_DATA} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) + +FILE(GLOB GUITXT_DATA "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.txt") +INSTALL(FILES ${GUITXT_DATA} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) + + + diff --git a/src/VTKViewer/VTKViewer_DataSetMapper.cxx b/src/VTKViewer/VTKViewer_DataSetMapper.cxx index d06e0a742..5d9888fa8 100644 --- a/src/VTKViewer/VTKViewer_DataSetMapper.cxx +++ b/src/VTKViewer/VTKViewer_DataSetMapper.cxx @@ -29,6 +29,7 @@ vtkStandardNewMacro(VTKViewer_DataSetMapper); VTKViewer_DataSetMapper::VTKViewer_DataSetMapper() { this->MarkerEnabled = false; + this->BallEnabled = false; this->MarkerType = VTK::MT_NONE; this->MarkerScale = VTK::MS_NONE; this->MarkerId = 0; @@ -54,7 +55,8 @@ void VTKViewer_DataSetMapper::Render(vtkRenderer *ren, vtkActor *act) pm->SetMarkerStd( this->MarkerType, this->MarkerScale ); else pm->SetMarkerTexture( this->MarkerId, this->MarkerTexture ); - + pm->SetBallEnabled( this->BallEnabled ); + this->GeometryExtractor = gf; this->PolyDataMapper = pm; } @@ -70,6 +72,17 @@ void VTKViewer_DataSetMapper::SetMarkerEnabled( bool theMarkerEnabled ) aMapper->SetMarkerEnabled( theMarkerEnabled ); } + +//----------------------------------------------------------------------------- +void VTKViewer_DataSetMapper::SetBallEnabled( bool theBallEnabled ) +{ + this->BallEnabled = theBallEnabled; + if( this->PolyDataMapper ) + if( VTKViewer_PolyDataMapper* aMapper = dynamic_cast( this->PolyDataMapper ) ) + aMapper->SetBallEnabled( theBallEnabled ); +} + + //---------------------------------------------------------------------------- void VTKViewer_DataSetMapper::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale ) { diff --git a/src/VTKViewer/VTKViewer_DataSetMapper.h b/src/VTKViewer/VTKViewer_DataSetMapper.h index 153b5a18a..2a8498b9a 100644 --- a/src/VTKViewer/VTKViewer_DataSetMapper.h +++ b/src/VTKViewer/VTKViewer_DataSetMapper.h @@ -33,6 +33,7 @@ public: //! Set point marker enabled void SetMarkerEnabled( bool ); + void SetBallEnabled( bool ); //! Set standard point marker void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale ); @@ -62,6 +63,7 @@ private: private: bool MarkerEnabled; + bool BallEnabled; VTK::MarkerType MarkerType; VTK::MarkerScale MarkerScale; int MarkerId; diff --git a/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.cxx b/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.cxx index b238f5e19..e45225081 100755 --- a/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.cxx +++ b/src/VTKViewer/VTKViewer_ExtractUnstructuredGrid.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -95,7 +96,7 @@ vtkIdType VTKViewer_ExtractUnstructuredGrid::GetOutputId(int theInId) const{ } -inline void InsertCell(vtkUnstructuredGrid *theInput, +inline int InsertCell(vtkUnstructuredGrid *theInput, vtkCellArray *theConnectivity, vtkUnsignedCharArray* theCellTypesArray, vtkIdTypeArray*& theFaces, @@ -110,6 +111,7 @@ inline void InsertCell(vtkUnstructuredGrid *theInput, vtkCell *aCell = theInput->GetCell(theCellId); vtkIdList *aPntIds = aCell->GetPointIds(); vtkIdType aNbIds = aPntIds->GetNumberOfIds(); + vtkIdType aCellId = -1; theIdList->SetNumberOfIds(aNbIds); for(vtkIdType i = 0; i < aNbIds; i++){ theIdList->SetId(i,aPntIds->GetId(i)); @@ -119,7 +121,7 @@ inline void InsertCell(vtkUnstructuredGrid *theInput, if (aCellType != VTK_POLYHEDRON) { #endif - theConnectivity->InsertNextCell(theIdList); + aCellId = theConnectivity->InsertNextCell(theIdList); if (theFaceLocations) theFaceLocations->InsertNextValue(-1); #if VTK_XVERSION > 50700 @@ -152,11 +154,12 @@ inline void InsertCell(vtkUnstructuredGrid *theInput, } #endif - theCellTypesArray->InsertNextValue(aCellType); + vtkIdType anID = theCellTypesArray->InsertNextValue(aCellType); if(theStoreMapping){ theOut2InId.push_back(theCellId); theIn2OutId[theCellId] = theOutId; } + return aCellId; } inline void InsertPointCell(vtkCellArray *theConnectivity, @@ -224,6 +227,7 @@ int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(re vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); aCellTypesArray->SetNumberOfComponents(1); aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents()); + anOutput->GetCellData()->CopyAllocate(anInput->GetCellData(),aNbElems,aNbElems/2); vtkIdTypeArray *newFaces = 0; vtkIdTypeArray *newFaceLocations = 0; @@ -233,15 +237,17 @@ int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(re if(myChangeMode == eAdding){ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){ if(myCellIds.find(aCellId) != myCellIds.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } }else{ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){ if(myCellIds.find(aCellId) == myCellIds.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } } @@ -250,16 +256,18 @@ int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(re for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){ vtkIdType aType = anInput->GetCellType(aCellId); if(myCellTypes.find(aType) != myCellTypes.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } }else{ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){ vtkIdType aType = anInput->GetCellType(aCellId); if(myCellTypes.find(aType) == myCellTypes.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } } @@ -269,8 +277,9 @@ int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(re vtkIdType aType = anInput->GetCellType(aCellId); if(myCellTypes.find(aType) != myCellTypes.end()){ if(myCellIds.find(aCellId) != myCellIds.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } } @@ -279,8 +288,9 @@ int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(re vtkIdType aType = anInput->GetCellType(aCellId); if(myCellTypes.find(aType) == myCellTypes.end()){ if(myCellIds.find(aCellId) == myCellIds.end()){ - InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, + vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList, myStoreMapping,anOutId,myOut2InId,myIn2OutId); + anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId); } } } diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx index dc0e23331..4719a6c73 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,9 @@ #include #include #include +#include +#include +#include #ifndef WNT # ifndef GLX_GLXEXT_LEGACY @@ -80,16 +84,42 @@ typedef ptrdiff_t GLsizeiptrARB; #define GL_ARRAY_BUFFER_ARB 0x8892 #define GL_STATIC_DRAW_ARB 0x88E4 #endif - +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); + +typedef GLfloat TBall; + + +static PFNGLSHADERSOURCEARBPROC vglShaderSourceARB = NULL; +static PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB = NULL; +static PFNGLCOMPILESHADERARBPROC vglCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC vglAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC vglLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB = NULL; + +static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL; +static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL; +static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL; +static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL; +static PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB = NULL; +static PFNGLVERTEXATTRIBPOINTERPROC vglVertexAttribPointerARB = NULL; +static PFNGLENABLEVERTEXATTRIBARRAYARBPROC vglEnableVertexAttribArrayARB = NULL; +static PFNGLDISABLEVERTEXATTRIBARRAYARBPROC vglDisableVertexAttribArrayARB = NULL; -static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL; -static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL; -static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL; -static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL; #ifndef WNT #define GL_GetProcAddress( x ) glXGetProcAddressARB( (const GLubyte*)x ) @@ -103,9 +133,41 @@ static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL #endif #endif +// ----------------------------------------------- Special Textures ----------------------------------- +// texture id for balls drawing +#define BallTextureId 0 bool InitializeBufferExtensions() { + + vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GL_GetProcAddress( "glShaderSourceARB" ); + if( !vglShaderSourceARB ) + return false; + + vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GL_GetProcAddress( "glCreateShaderObjectARB" ); + if( !vglCreateShaderObjectARB ) + return false; + + vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GL_GetProcAddress( "glCompileShaderARB" ); + if( !vglCompileShaderARB ) + return false; + + vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glCreateProgramObjectARB" ); + if( !vglCreateProgramObjectARB ) + return false; + + vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GL_GetProcAddress( "glAttachObjectARB" ); + if( !vglAttachObjectARB ) + return false; + + vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GL_GetProcAddress( "glLinkProgramARB" ); + if( !vglLinkProgramARB ) + return false; + + vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glUseProgramObjectARB" ); + if( !vglUseProgramObjectARB ) + return false; + vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GL_GetProcAddress( "glGenBuffersARB" ); if( !vglGenBuffersARB ) return false; @@ -122,9 +184,53 @@ bool InitializeBufferExtensions() if( !vglDeleteBuffersARB ) return false; + vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GL_GetProcAddress( "glGetAttribLocation" ); + if( !vglGetAttribLocationARB ) + return false; + + vglVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERPROC)GL_GetProcAddress( "glVertexAttribPointer" ); + if( !vglVertexAttribPointerARB ) + return false; + + vglEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glEnableVertexAttribArray" ); + if(!vglEnableVertexAttribArrayARB) + return false; + + vglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glDisableVertexAttribArray" ); + + if(!vglDisableVertexAttribArrayARB) + return false; + + return true; }; +//----------------------------------------------------------------------------- +char* readFromFile( std::string fileName ) +{ + FILE* file = fopen( fileName.c_str(), "r" ); + + char* content = NULL; + int count = 0; + + if( file != NULL ) + { + fseek( file, 0, SEEK_END ); + count = ftell( file ); + rewind( file ); + + if( count > 0 ) + { + content = ( char* )malloc( sizeof( char ) * ( count + 1 ) ); + count = fread( content, sizeof( char ), count, file ); + content[ count ] = '\0'; + } + fclose( file ); + } + + return content; +} + static bool IsBufferExtensionsInitialized = InitializeBufferExtensions(); //----------------------------------------------------------------------------- @@ -140,6 +246,7 @@ VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper() this->MarkerType = VTK::MT_NONE; this->MarkerScale = VTK::MS_NONE; this->MarkerId = 0; + this->BallEnabled = false; } //----------------------------------------------------------------------------- @@ -149,6 +256,26 @@ VTKViewer_PolyDataMapper::~VTKViewer_PolyDataMapper() glDeleteTextures( 1, &PointSpriteTexture ); } +//----------------------------------------------------------------------------- +void VTKViewer_PolyDataMapper::InitShader() +{ + std::string fileName = std::string( getenv( "GUI_ROOT_DIR") ) + + "/share/salome/resources/gui/Vertex_Program_ARB.txt"; + + char* shader = readFromFile( fileName ); + + GLhandleARB VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); + vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); + vglCompileShaderARB( VertexShader ); + + this->VertexProgram = vglCreateProgramObjectARB(); + vglAttachObjectARB( this->VertexProgram, VertexShader ); + + vglLinkProgramARB( this->VertexProgram ); + free( shader ); +} + + //----------------------------------------------------------------------------- void VTKViewer_PolyDataMapper::SetMarkerEnabled( bool theMarkerEnabled ) { @@ -159,6 +286,96 @@ void VTKViewer_PolyDataMapper::SetMarkerEnabled( bool theMarkerEnabled ) this->Modified(); } +//----------------------------------------------------------------------------- +// Definition of structures and fuctions used in SetBallEnabled() method +namespace VTK +{ + //---------------------------------------------------------------------------- + vtkSmartPointer MakeTexture( const char* theMainTexture, const char* theAlphaTexture ) { + if( !theMainTexture || !theAlphaTexture ) + return 0; + + vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New(); + vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New(); + + aMainReader->SetFileName( theMainTexture ); + anAlphaReader->SetFileName( theAlphaTexture ); + + 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]) + return NULL; + + vtkSmartPointer aCompositeImageData = vtkImageData::New(); + aCompositeImageData->Delete(); + + int aNbCompositeComponents = 4; + aCompositeImageData->SetDimensions(aMainImageSize); + aCompositeImageData->AllocateScalars( VTK_UNSIGNED_CHAR, aNbCompositeComponents ); + + unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer(); + unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer(); + unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer(); + + int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents(); + int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents(); + int aCompositeSize = aMainImageSize[0] * aMainImageSize[1] * aNbCompositeComponents; + + int aMainId = 0, anAlphaId = 0, aCompositeId = 0; + for(; aCompositeId < aCompositeSize;) { + 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; + } + aMainReader->Delete(); + anAlphaReader->Delete(); + return aCompositeImageData; + } +} + +//----------------------------------------------------------------------------- +bool VTKViewer_PolyDataMapper::GetBallEnabled() +{ + return this->BallEnabled; +} +//----------------------------------------------------------------------------- +void VTKViewer_PolyDataMapper::SetBallEnabled( bool theBallEnabled ) +{ + if( this->BallEnabled == theBallEnabled ) + return; + else + this->BallEnabled = theBallEnabled; + + if(!this->BallEnabled) { + this->ImageData = NULL; + } + + if(this->BallEnabled) { + if(this->SpecialTextures.find(BallTextureId) == SpecialTextures.end()){ + QString aMainTexture = getenv( "GUI_ROOT_DIR" ); + aMainTexture.append("/share/salome/resources/gui/sprite_texture.vti"); + + QString anAlphaTexture = getenv( "GUI_ROOT_DIR" ); + anAlphaTexture.append( "/share/salome/resources/gui/sprite_alpha.vti" ); + vtkSmartPointer aTextureValue = VTK::MakeTexture( aMainTexture.toLatin1().constData(), anAlphaTexture.toLatin1().constData() ); + this->SpecialTextures[BallTextureId] = aTextureValue; + } + this->ImageData = this->SpecialTextures[BallTextureId]; + } + this->Modified(); +} + //----------------------------------------------------------------------------- void VTKViewer_PolyDataMapper::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale ) { @@ -231,12 +448,16 @@ int VTKViewer_PolyDataMapper::InitExtensions() char* ext = (char*)glGetString( GL_EXTENSIONS ); if( !IsBufferExtensionsInitialized || strstr( ext, "GL_ARB_point_sprite" ) == NULL || - strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL ) + strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL || + strstr( ext, "GL_ARB_shader_objects") == NULL ) { MESSAGE("Initializing ARB extensions failed"); return ES_Error; } + if( this->BallEnabled ) + this->InitShader(); + return ES_Ok; } @@ -252,7 +473,12 @@ void VTKViewer_PolyDataMapper::InitPointSprites() glEnable( GL_DEPTH_TEST ); glEnable( GL_ALPHA_TEST ); - glAlphaFunc( GL_GREATER, 0.0 ); + if(!this->BallEnabled) { + glAlphaFunc( GL_GREATER, 0.0 ); + } + else { + glAlphaFunc( GL_GREATER, 0.5 ); + } glDisable( GL_LIGHTING ); @@ -276,8 +502,14 @@ void VTKViewer_PolyDataMapper::InitTextures() 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_MIN_FILTER, GL_NEAREST ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + + if(this->BallEnabled) { + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + } else { + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + } int* aSize = this->ImageData->GetDimensions(); unsigned char* dataPtr = (unsigned char*)this->ImageData->GetScalarPointer(); @@ -293,7 +525,8 @@ void VTKViewer_PolyDataMapper::InitTextures() //----------------------------------------------------------------------------- void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) { - bool isUsePointSprites = this->MarkerEnabled && this->MarkerType != VTK::MT_NONE; + bool isUsePointSprites = (this->MarkerEnabled && this->MarkerType != VTK::MT_NONE) || + this->BallEnabled; if( isUsePointSprites ) { if( this->ExtensionsInitialized == ES_None ) @@ -302,10 +535,122 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) this->InitTextures(); } - MAPPER_SUPERCLASS::RenderPiece( ren, act ); + if(!this->BallEnabled) { + MAPPER_SUPERCLASS::RenderPiece( ren, act ); + if( isUsePointSprites ) + this->CleanupPointSprites(); + } else { + vtkIdType numPts; + vtkPolyData *input= this->GetInput(); + + // + // make sure that we've been properly initialized + // + if (ren->GetRenderWindow()->CheckAbortStatus()) + return; + + if ( input == NULL ) + { + vtkErrorMacro(<< "No input!"); + return; + } + else + { + this->InvokeEvent(vtkCommand::StartEvent,NULL); + this->Update(); + this->InvokeEvent(vtkCommand::EndEvent,NULL); + numPts = input->GetNumberOfPoints(); + } + + if (numPts == 0) + { + vtkDebugMacro(<< "No points!"); + return; + } + + // make sure our window is current + ren->GetRenderWindow()->MakeCurrent(); + + + vglUseProgramObjectARB( this->VertexProgram ); + + // + // if something has changed regenerate colors and display lists + // if required + // + int noAbort=1; + if ( this->GetMTime() > this->BuildTime || + input->GetMTime() > this->BuildTime || + act->GetProperty()->GetMTime() > this->BuildTime || + ren->GetRenderWindow() != this->LastWindow) + { + // sets this->Colors as side effect + this->MapScalars( act->GetProperty()->GetOpacity() ); + + if (!this->ImmediateModeRendering && + !this->GetGlobalImmediateModeRendering()) + { + this->ReleaseGraphicsResources(ren->GetRenderWindow()); + this->LastWindow = ren->GetRenderWindow(); + + // get a unique display list id + this->ListId = glGenLists(1); + glNewList(this->ListId,GL_COMPILE); + + noAbort = this->Draw(ren,act); + glEndList(); + + // Time the actual drawing + this->Timer->StartTimer(); + glCallList(this->ListId); + this->Timer->StopTimer(); + } + else + { + this->ReleaseGraphicsResources(ren->GetRenderWindow()); + this->LastWindow = ren->GetRenderWindow(); + } + if (noAbort) + this->BuildTime.Modified(); + } + // if nothing changed but we are using display lists, draw it + else + { + if (!this->ImmediateModeRendering && + !this->GetGlobalImmediateModeRendering()) + { + // Time the actual drawing + this->Timer->StartTimer(); + glCallList(this->ListId); + this->Timer->StopTimer(); + } + } + + // if we are in immediate mode rendering we always + // want to draw the primitives here + if (this->ImmediateModeRendering || + this->GetGlobalImmediateModeRendering()) + { + // sets this->Colors as side effect + this->MapScalars( act->GetProperty()->GetOpacity() ); + + // Time the actual drawing + this->Timer->StartTimer(); + this->Draw(ren,act); + this->Timer->StopTimer(); + } + + this->TimeToDraw = (float)this->Timer->GetElapsedTime(); + + // If the timer is not accurate enough, set it to a small + // time so that it is not zero + if ( this->TimeToDraw == 0.0 ) + this->TimeToDraw = 0.0001; + + vglUseProgramObjectARB( 0 ); - if( isUsePointSprites ) this->CleanupPointSprites(); + } } //----------------------------------------------------------------------------- @@ -424,11 +769,18 @@ namespace VTK TColorFunctorBase* theColorFunctor, TVertex* theVertexArr, vtkIdType &theCellId, - vtkIdType &theVertexId ) + vtkIdType &theVertexId, + TBall* theBallArr, + vtkDataArray* theDiamArray) { vtkIdType* ptIds = theCells->GetPointer(); vtkIdType* endPtIds = ptIds + theCells->GetNumberOfConnectivityEntries(); + bool mapBalls = false; + if(theBallArr && theDiamArray) { + mapBalls = true; + } + while ( ptIds < endPtIds ) { vtkIdType nPts = *ptIds; ++ptIds; @@ -448,6 +800,10 @@ namespace VTK ++ptIds; --nPts; } + + if(mapBalls){ + theBallArr[theCellId] = (TBall)theDiamArray->GetTuple(theCellId)[0]; + } ++theCellId; } @@ -458,30 +814,33 @@ namespace VTK void DrawCellsPoints( vtkPolyData* theInput, vtkPoints* thePoints, TColorFunctorBase* theColorFunctor, - TVertex* theVertexArr ) + TVertex* theVertexArr, + TBall* theBallArr) { vtkIdType aCellId = 0, aVertexId = 0; TCoordinates* aStartPoints = (TCoordinates*)thePoints->GetVoidPointer(0); + vtkDataArray* aDiams = theInput->GetCellData() ? theInput->GetCellData()->GetScalars() : 0; - if ( vtkCellArray* aCellArray = theInput->GetVerts() ) - DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId ); + if ( vtkCellArray* aCellArray = theInput->GetVerts() ) { + DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams); + } if ( vtkCellArray* aCellArray = theInput->GetLines() ) - DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId ); + DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams); if ( vtkCellArray* aCellArray = theInput->GetPolys() ) - DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId ); + DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams); if ( vtkCellArray* aCellArray = theInput->GetStrips() ) - DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId ); + DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams); } } // namespace VTK //----------------------------------------------------------------------------- int VTKViewer_PolyDataMapper::Draw( vtkRenderer* ren, vtkActor* act ) -{ - if( !this->MarkerEnabled || this->MarkerType == VTK::MT_NONE || !this->ImageData.GetPointer() ) +{ + if( (!this->MarkerEnabled || this->MarkerType == VTK::MT_NONE || !this->ImageData.GetPointer()) && !this->BallEnabled) return MAPPER_SUPERCLASS::Draw( ren, act ); vtkUnsignedCharArray* colors = NULL; @@ -495,31 +854,48 @@ int VTKViewer_PolyDataMapper::Draw( vtkRenderer* ren, vtkActor* act ) if ( this->Colors ) { - colors = this->Colors; - if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA || - this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA || - !input->GetPointData()->GetScalars() ) - && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) - cellScalars = 1; + if(!this->BallEnabled) { + colors = this->Colors; + if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA || + this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA || + !input->GetPointData()->GetScalars() ) + && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA ) + cellScalars = 1; + } } { vtkIdType aTotalConnectivitySize = 0; + vtkIdType aNbCells = 0; - if ( vtkCellArray* aCellArray = input->GetVerts() ) + if ( vtkCellArray* aCellArray = input->GetVerts() ) { aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells(); + aNbCells += aCellArray->GetNumberOfCells(); + } - if ( vtkCellArray* aCellArray = input->GetLines() ) + if ( vtkCellArray* aCellArray = input->GetLines() ) { aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells(); + aNbCells += aCellArray->GetNumberOfCells(); + } - if ( vtkCellArray* aCellArray = input->GetPolys() ) + if ( vtkCellArray* aCellArray = input->GetPolys() ) { aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells(); + aNbCells += aCellArray->GetNumberOfCells(); + } - if ( vtkCellArray* aCellArray = input->GetStrips() ) + if ( vtkCellArray* aCellArray = input->GetStrips() ) { aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells(); + aNbCells += aCellArray->GetNumberOfCells(); + } if ( aTotalConnectivitySize > 0 ) { VTK::TVertex* aVertexArr = new VTK::TVertex[ aTotalConnectivitySize ]; + + TBall* aBallArray = 0; + + if(this->BallEnabled) { + aBallArray = new TBall[aNbCells]; + } int* aSize = this->ImageData->GetDimensions(); glPointSize( std::max( aSize[0], aSize[1] ) ); @@ -536,15 +912,16 @@ int VTKViewer_PolyDataMapper::Draw( vtkRenderer* ren, vtkActor* act ) aColorFunctor = new VTK::TPropertyColor( prop ); } if ( points->GetDataType() == VTK_FLOAT ) - VTK::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr ); + VTK::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr, aBallArray ); else - VTK::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr ); + VTK::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr, aBallArray ); delete aColorFunctor; } if( this->ExtensionsInitialized == ES_Ok ) { - GLuint aBufferObjectID = 0; + GLuint aBufferObjectID, aDiamsID = 0; + GLint attribute_diams = -1; vglGenBuffersARB( 1, &aBufferObjectID ); vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); @@ -554,20 +931,49 @@ int VTKViewer_PolyDataMapper::Draw( vtkRenderer* ren, vtkActor* act ) delete [] aVertexArr; vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); glColorPointer( 4, GL_FLOAT, sizeof(VTK::TVertex), (void*)0 ); glVertexPointer( 3, GL_FLOAT, sizeof(VTK::TVertex), (void*)(4*sizeof(GLfloat)) ); glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); - + + if(this->BallEnabled) { + vglGenBuffersARB( 2, &aDiamsID); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID); + + int aDiamsSize = sizeof(TBall)*aNbCells; + vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB); + + delete [] aBallArray; + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID ); + + attribute_diams = vglGetAttribLocationARB(this->VertexProgram, "diameter"); + vglEnableVertexAttribArrayARB(attribute_diams); + vglBindBufferARB(GL_ARRAY_BUFFER, aDiamsID); + vglVertexAttribPointerARB( + attribute_diams, // attribute + 1, // number of elements per vertex, here (diameter) + GL_FLOAT, // the type of each element + GL_FALSE, // take our values as-is + 0, // no extra data between each position + 0 // offset of first element + ); + } + glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize ); glDisableClientState( GL_COLOR_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); - + glDisableClientState( GL_VERTEX_ARRAY ); vglDeleteBuffersARB( 1, &aBufferObjectID ); + + if(this->BallEnabled) { + vglDisableVertexAttribArrayARB(attribute_diams); + vglDeleteBuffersARB( 2, &aDiamsID ); + } + } else { // there are no extensions glColorPointer( 4, GL_FLOAT, sizeof(VTK::TVertex), aVertexArr ); glVertexPointer( 3, GL_FLOAT, sizeof(VTK::TVertex), diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.h b/src/VTKViewer/VTKViewer_PolyDataMapper.h index 0ea770e4b..d7e378310 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.h +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.h @@ -65,6 +65,11 @@ public: //! Set point marker enabled void SetMarkerEnabled( bool ); + //! Set point ball enabled + void SetBallEnabled( bool ); + + bool GetBallEnabled( ); + //! Set standard point marker void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale ); @@ -102,14 +107,20 @@ protected: //! Initializing textures for Point Sprites. void InitTextures(); + //! Initializing of the Vertex Shader. + void InitShader(); + private: int ExtensionsInitialized; GLuint PointSpriteTexture; vtkSmartPointer ImageData; + + GLhandleARB VertexProgram; bool MarkerEnabled; + bool BallEnabled; VTK::MarkerType MarkerType; VTK::MarkerScale MarkerScale; int MarkerId; @@ -117,6 +128,7 @@ private: typedef std::map< int, vtkSmartPointer > ImageDataMap; ImageDataMap StandardTextures; ImageDataMap CustomTextures; + ImageDataMap SpecialTextures; //special predefined textures, used to draw point sprites. }; #endif diff --git a/src/VTKViewer/resources/Vertex_Program_ARB.txt b/src/VTKViewer/resources/Vertex_Program_ARB.txt new file mode 100644 index 000000000..46d01a88f --- /dev/null +++ b/src/VTKViewer/resources/Vertex_Program_ARB.txt @@ -0,0 +1,8 @@ +attribute float diameter; + +void main() +{ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_FrontColor = gl_Color; + gl_PointSize = 1400 * gl_ProjectionMatrix[1].y * diameter; +} diff --git a/src/VTKViewer/resources/sprite_alpha.vti b/src/VTKViewer/resources/sprite_alpha.vti new file mode 100644 index 000000000..97b3fdf96 --- /dev/null +++ b/src/VTKViewer/resources/sprite_alpha.vti @@ -0,0 +1,15 @@ + + + + + + + + + + + + + _AQAAAACAAAAAAwAApQAAAA==eJzVkLERhCAQRa3AiIjQDmxCMiLJjK3AlBIIwZAe7AFiupACiOH+GNx4M8LF/vjt7n/bdS8IpXQYhr7v/5LA1nVVShljpJTTNDVgQsi2bd77cuU8T2stY6zGY9txHOWWGCOu1IotyxJCKL/RWqPkIz/Ps3PuDuec4QL9R34cx33fU0pfHuPQbyhzzlEAGIrBBfq1MvcrQgi44DP4WBt+XT5+l3QU + + diff --git a/src/VTKViewer/resources/sprite_texture.vti b/src/VTKViewer/resources/sprite_texture.vti new file mode 100644 index 000000000..97281c4bb --- /dev/null +++ b/src/VTKViewer/resources/sprite_texture.vti @@ -0,0 +1,15 @@ + + + + + + + + + + + + + _AQAAAACAAAAAAwAA3AEAAA==eJylkr+L2mAcxv2RnIGkySkRTkUEMXURBxtz2ZpBHJJzSC+biIeLW0TSHrgILndEepOTAW9LoQfN4A06u8Q/QCfH65rOjn1AauEqpdB3egnPN9/n+TxvKPRfJ0oQNE2fx+OJRIJjOSoWC4fDJ5X4zrxhstlsqVSSpKp8KVcqFUEQkskkSZJ/iEMcyxaLRUVRjGvjpt3udDrNZlNTNVEU0+n0qxGKogqFQq1Wg2wwGNzd3dtjezQamaZ5bRjvRJHn+aMxXHg+eSnLrVZrOBw6juN53vx57rruw8Nns9dTNVV4K1BU7KAnCCKXy9XrdfxtMpksl8vtZrvb7fz1+ovrYguMIQvLcQc9vMFM4+rq9tPt42y29v0gCPb7PUae53PbtmFSlmUQO+rz+bymqpZlOc50tVq9vHz/EQSb7cb75iFL+6ZdlaR4/Pygj0QimUwGZLrd7tgeP319woi/9heLhTN1EN8wDEBmaPrIB9WUy+UPut7v92Fg6jiz2SOyID7MKO8V9EIQ0d+1RqOp1IVUlXRdxxbL+ogsvZ4JYoCMXhiGeVXZ2RmZukhhC4ypqtZoNEAMkIECVZ58FdjCsizaRHzIABmPAVWefkC/DuKTJAFoGP+r8J/OTxIOlB8= + +