From 59748c3d553ac4ab6ea9660f5c017f046ee21bbd Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 23 Sep 2005 13:53:50 +0000 Subject: [PATCH] MakeTexture() moved from VISU_GaussPoints_I --- src/PIPELINE/VISU_GaussPointsPL.cxx | 60 +++++++++++++++++++++++++++++ src/PIPELINE/VISU_GaussPointsPL.hxx | 5 +++ 2 files changed, 65 insertions(+) diff --git a/src/PIPELINE/VISU_GaussPointsPL.cxx b/src/PIPELINE/VISU_GaussPointsPL.cxx index 85802771..c3f68e91 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.cxx +++ b/src/PIPELINE/VISU_GaussPointsPL.cxx @@ -367,3 +367,63 @@ VISU_GaussPointsPL { myPSMapper->SetImageData( theImageData ); } + +//---------------------------------------------------------------------------- +vtkImageData* +VISU_GaussPointsPL +::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]) + 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(); + + 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(); + aCompositeImageData->Update(); + + return aCompositeImageData; +} diff --git a/src/PIPELINE/VISU_GaussPointsPL.hxx b/src/PIPELINE/VISU_GaussPointsPL.hxx index 3d9cab66..192542ae 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.hxx +++ b/src/PIPELINE/VISU_GaussPointsPL.hxx @@ -159,6 +159,11 @@ public: void SetImageData(vtkImageData* theImageData); + static + vtkImageData* + MakeTexture( const char* theMainTexture, + const char* theAlphaTexture ); + protected: VISU_OpenGLPointSpriteMapper* myPSMapper; vtkGeometryFilter* myGeomFilter; -- 2.39.2