From: rnv Date: Tue, 22 Apr 2008 11:29:05 +0000 (+0000) Subject: Start visualization of ELNO field. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=72a838b0e79100bf32330d021082abe6be361d81;p=modules%2Fvisu.git Start visualization of ELNO field. --- diff --git a/src/CONVERTOR/VISU_ConvertorUtils.cxx b/src/CONVERTOR/VISU_ConvertorUtils.cxx index 85f49eec..53a2708a 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.cxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.cxx @@ -233,6 +233,16 @@ namespace VISU return aDataSetAttributes->GetArray("VISU_FIELD") != NULL; } + //--------------------------------------------------------------- + bool + IsDataOnElnoCells(vtkDataSet* theDataSet) + { + theDataSet->Update(); + vtkDataSetAttributes *aDataSetAttributes = theDataSet->GetCellData(); + return (aDataSetAttributes->GetArray("ELNO_FIELD") != NULL && + aDataSetAttributes->GetArray("ELNO_COMPONENT_MAPPER") != NULL); + } + //--------------------------------------------------------------- vtkIdType diff --git a/src/CONVERTOR/VISU_ConvertorUtils.hxx b/src/CONVERTOR/VISU_ConvertorUtils.hxx index 17c12fde..0b19a68d 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.hxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.hxx @@ -90,6 +90,11 @@ namespace VISU bool IsDataOnCells(vtkDataSet* theDataSet); + //--------------------------------------------------------------- + VISU_CONVERTOR_EXPORT + bool + IsDataOnElnoCells(vtkDataSet* theDataSet); + //--------------------------------------------------------------- VISU_CONVERTOR_EXPORT diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index c8bdc2d1..ad0f502a 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -886,7 +886,8 @@ VISU_Convertor_impl if(!isNeedInCells){ vtkUnstructuredGrid* anOutput = theUnstructuredGridIDMapper->GetUnstructuredGridOutput(); const VISU::PUnstructuredGrid& aSource = theUnstructuredGridIDMapper->mySource.GetSource(); - VISU::GetTimeStampOnProfile(aSource, theField, theValForTime, theEntity); + //VISU::GetTimeStampOnProfile(aSource, theField, theValForTime, theEntity); + VISU::GetElnoTimeStamp(aSource, theField, theValForTime, theEntity); } return anOutput; } diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index b10aa67e..77f1d06c 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -146,6 +146,7 @@ namespace case MED::eNOEUD: return VISU::NODE_ENTITY; case MED::eARETE: return VISU::EDGE_ENTITY; case MED::eFACE: return VISU::FACE_ENTITY; + case MED::eNOEUD_ELEMENT: case MED::eMAILLE: return VISU::CELL_ENTITY; } return VISU::TEntity(-1); diff --git a/src/CONVERTOR/VISU_MeshValue.cxx b/src/CONVERTOR/VISU_MeshValue.cxx index 4b7a2785..195f333c 100644 --- a/src/CONVERTOR/VISU_MeshValue.cxx +++ b/src/CONVERTOR/VISU_MeshValue.cxx @@ -610,6 +610,202 @@ namespace VISU aFullDataArray->Delete(); } - + //--------------------------------------------------------------- + template + void + InitElnoTimeStamp(const PUnstructuredGrid& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity); + + + //---------------------------------------------------------------------------- + void + GetElnoTimeStamp(const PUnstructuredGrid& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity) + { + vtkIdType aDataType = theField->GetDataType(); + switch(aDataType){ + case VTK_DOUBLE: + InitElnoTimeStamp(theSource, theField, theValForTime, theEntity); + break; + case VTK_FLOAT: + InitElnoTimeStamp(theSource, theField, theValForTime, theEntity); + break; + case VTK_INT: + InitElnoTimeStamp(theSource, theField, theValForTime, theEntity); + break; + case VTK_LONG: + InitElnoTimeStamp(theSource, theField, theValForTime, theEntity); + break; + default: + EXCEPTION(std::runtime_error, + "GetElnoTimeStamp - handling unsupported data type - "< + struct TTimeStampOnElnoInitArray + { + typedef typename TL::TEnum2VTKArrayType::TResult TVTKDataArray; + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef MED::SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef MED::SharedPtr PDataArrayHolder; + PDataArrayHolder myDataArrayHolder; + vtkIntArray *myComponentMapper; + vtkIdType myComponentStep; + + TTimeStampOnElnoInitArray(const PDataArrayHolder& theDataArrayHolder, vtkIntArray * aComponentMapper=0): + myDataArrayHolder(theDataArrayHolder), + myComponentStep(0), + myComponentMapper(aComponentMapper) + {} + + void SetComponentStep(vtkIdType& theStep){ + myComponentStep = theStep; + } + + void + Execute(const PFieldImpl& theField, + const PValForTimeImpl& theValForTime) + { + vtkIdType aNbComp = theField->myNbComp; + TVector aDataValues(myComponentStep+1); + + vtkIdType componentCount=0,aTupleId=0,aNextStartId=0,aComponentTupleId=0; + int theTuple[3] = {aNextStartId, + theField->myNbComp, + 0}; + + const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue(); + TGeom2MeshValue::const_iterator anIter = aGeom2MeshValue.begin(); + for(; anIter != aGeom2MeshValue.end(); anIter++){ + EGeometry aEGeom = anIter->first; + const TMeshValuePtr aMeshValue = anIter->second; + + vtkIdType aNbElem = aMeshValue->GetNbElem(); + vtkIdType aNbGauss = aMeshValue->GetNbGauss(); + + INITMSG(MYDEBUG, + "- aEGeom = "<AddArray(aComponentMapper); + + TVTKDataArray *aFullDataArray = TVTKDataArray::New(); + aFullDataArray->SetNumberOfComponents(aEffectNbComp); + aFullDataArray->SetNumberOfTuples(aNbTuples); + aFullDataArray->SetName("ELNO_FIELD"); + + aDataSetAttributes->AddArray(aFullDataArray); + + INITMSG(MYDEBUG,"InitElnoTimeStamp "<< + "- theEntity = "<::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef MED::SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef MED::SharedPtr PDataArrayHolder; + + TMeshValuePtr aMeshValue = theValForTime->GetFirstMeshValue(); + + typedef TDataArrayHolder2 TTDataArrayHolder2; + PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder2(aSelectedDataArray, aFullDataArray)); + TTimeStampOnElnoInitArray aArrayInitializer(aDataArrayHolder,aComponentMapper); + aArrayInitializer.SetComponentStep(aEffectNbComp); + aArrayInitializer.Execute(theField, theValForTime); + + + aSelectedDataArray->Delete(); + aFullDataArray->Delete(); + } + } diff --git a/src/CONVERTOR/VISU_MeshValue.hxx b/src/CONVERTOR/VISU_MeshValue.hxx index f09fb783..1748c1a4 100644 --- a/src/CONVERTOR/VISU_MeshValue.hxx +++ b/src/CONVERTOR/VISU_MeshValue.hxx @@ -214,6 +214,13 @@ namespace VISU //--------------------------------------------------------------- + // Initilize corresponding vtkDataSetAttributes for TValForTime + void + GetElnoTimeStamp(const PUnstructuredGrid& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity); + } #endif diff --git a/src/CONVERTOR/VISU_Structures_impl.cxx b/src/CONVERTOR/VISU_Structures_impl.cxx index 7c269284..88da9b1d 100644 --- a/src/CONVERTOR/VISU_Structures_impl.cxx +++ b/src/CONVERTOR/VISU_Structures_impl.cxx @@ -719,8 +719,10 @@ namespace VISU aFilter->SetVectors(aDataSet); aFilter->AddField("VISU_FIELD",aDataSet); aFilter->AddField("VISU_CELLS_MAPPER",aDataSet); + aFilter->AddField("ELNO_FIELD",aDataSet); + aFilter->AddField("ELNO_COMPONENT_MAPPER",aDataSet); aFilter->AddField("VISU_POINTS_MAPPER",aDataSet); - + myCommonCellsFilter->SetProfileUG(aFilter->GetUnstructuredGridOutput()); } return myCommonCellsFilter->GetOutput(); diff --git a/src/PIPELINE/Makefile.am b/src/PIPELINE/Makefile.am index 34ae81b0..ec469cc7 100644 --- a/src/PIPELINE/Makefile.am +++ b/src/PIPELINE/Makefile.am @@ -64,7 +64,9 @@ salomeinclude_HEADERS= \ VISU_SphereWidget.hxx \ VISU_WidgetCtrl.hxx \ VISU_ScalarMapOnDeformedShapePL.hxx \ - VISUPipeline.hxx + VISU_OpenGLElnoMapper.hxx \ + VISUPipeline.hxx \ + VISU_ElnoGeometryFilter.hxx dist_libVisuPipeLine_la_SOURCES= \ VISU_MapperHolder.cxx \ @@ -101,7 +103,10 @@ dist_libVisuPipeLine_la_SOURCES= \ VISU_SphereWidget.cxx \ VISU_WidgetCtrl.cxx \ VISU_ScalarBarCtrl.cxx \ - VISU_ScalarMapOnDeformedShapePL.cxx + VISU_ScalarMapOnDeformedShapePL.cxx \ + VISU_OpenGLElnoMapper.cxx \ + VISU_ElnoGeometryFilter.cxx + libVisuPipeLine_la_CPPFLAGS= \ $(VTK_INCLUDES) \ diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx index 307f99f9..80384b76 100644 --- a/src/PIPELINE/VISUPipeLine.cxx +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -24,6 +24,10 @@ // Author: Alexey PETROV // Module : VISU + +// Salome includes +#include "VISU_Convertor.hxx" +#include "VISU_ConvertorUtils.hxx" #include "VISU_MeshPL.hxx" #include "VISU_ScalarMapPL.hxx" #include "VISU_IsoSurfacesPL.hxx" @@ -34,353 +38,275 @@ #include "VISU_StreamLinesPL.hxx" #include "VISU_GaussPointsPL.hxx" #include "VISU_ScalarMapOnDeformedShapePL.hxx" +#include "VISU_OpenGLElnoMapper.hxx" #include "VISU_Plot3DPL.hxx" #include "VISU_ScalarBarActor.hxx" - -#include "VISU_DeformedGridPL.hxx" - #include "VISU_OpenGLPointSpriteMapper.hxx" #include "VTKViewer_GeometryFilter.h" -#include - -#include "VISU_Convertor.hxx" -#include "VISU_TableReader.hxx" -#include "VISU_ConvertorUtils.hxx" - -typedef VISU_StreamLinesPL TPresent; +#include "VISU_ElnoGeometryFilter.hxx" +// VTK includes +#include +#include #include #include - #include #include #include #include +#include #include #include #include #include - #include -#include - -#include - -//#define _DEBUG_ID_MAPPING_ - -//---------------------------------------------------------------------------- -template -VISU_ColoredPL* -CreateColoredPL(VISU_Convertor* theConvertor, - const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theTimeStampNumber); - - -//---------------------------------------------------------------------------- -template<> -VISU_ColoredPL* -CreateColoredPL(VISU_Convertor* theConvertor, - const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theTimeStampNumber) -{ - VISU_GaussPointsPL* aPresent = VISU_GaussPointsPL::New(); - VISU::PGaussPtsIDMapper aGaussPtsIDMapper = - theConvertor->GetTimeStampOnGaussPts(theMeshName, - theEntity, - theFieldName, - theTimeStampNumber); - aPresent->SetGaussPtsIDMapper(aGaussPtsIDMapper); - - char aMainTexture[80]; - strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) ); - strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.bmp" ); +void PrintMissing(){ + cout<<"VISUPipeLine : "; + cout<<"missing operand after `VISUPipeLine'"< aTextureValue = - VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture ); - aPresent->SetImageData( aTextureValue.GetPointer() ); - - aPresent->Update(); - -#ifdef _DEBUG_ID_MAPPING_ - vtkDataSet* aDataSet = aPresent->GetOutput(); - aDataSet->Update(); - int aNbCells = aDataSet->GetNumberOfCells(); - cout<<"aNbCells = "<GetNodeObjID(anCellId); - vtkIdType aVtkID = aPresent->GetNodeVTKID(anObjID); - cout<GetNodeCoord(anObjID); - cout< -VISU_ColoredPL* -CreateColoredPL(VISU_Convertor* theConvertor, - const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theTimeStampNumber) -{ - TPipeLine* aPresent = TPipeLine::New(); - VISU::PUnstructuredGridIDMapper anUnstructuredGridIDMapper = - theConvertor->GetTimeStampOnMesh(theMeshName, - theEntity, - theFieldName, - theTimeStampNumber); - aPresent->SetUnstructuredGridIDMapper(anUnstructuredGridIDMapper); - - //aPresent->ClearGeometry(); - //{ - // VISU::PUnstructuredGridIDMapper anIDMapper = - // theConvertor->GetMeshOnGroup(theMeshName, - // "groupe1"); - // aPresent->AddGeometry(anIDMapper->GetOutput()); - //} - //{ - // VISU::PUnstructuredGridIDMapper anIDMapper = - // theConvertor->GetMeshOnGroup(theMeshName, - // "TUBEH "); - // aPresent->AddGeometry(anIDMapper->GetOutput()); - //} - //{ - // VISU::PUnstructuredGridIDMapper anIDMapper = - // theConvertor->GetMeshOnGroup(theMeshName, - // "STRI "); - // aPresent->AddGeometry(anIDMapper->GetOutput()); - //} - aPresent->Update(); - return aPresent; +void PrintHelp(){ + + cout<<" Usage: VISUPipeLine filename meshname fieldname [timestamp] [component] " < myConvertor; - - TMEDSource(char** argv): myConvertor(CreateConvertor(argv[1])) - { - myConvertor->BuildEntities(); - } -}; - - -//---------------------------------------------------------------------------- -struct TMeshBulder: TMEDSource -{ - TMeshBulder(char** argv): TMEDSource(argv) - {} - - int Publish(vtkRenderer *theRenderer) const - { - const VISU::TMeshMap& aMeshMap = myConvertor->GetMeshMap(); - VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - if(aMeshMapIter == aMeshMap.end()) - return 0; - - const std::string& aMeshName = aMeshMapIter->first; - const VISU::PMesh aMesh = aMeshMapIter->second; - const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; - - VISU::TEntity anEntity = VISU::CELL_ENTITY; - aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity); - - VISU::PNamedIDMapper anIDMapper = myConvertor->GetMeshOnEntity(aMeshName, anEntity); - - VISU_MeshPL* aPresent = VISU_MeshPL::New(); - aPresent->SetUnstructuredGridIDMapper(anIDMapper); - - vtkActor* anActor = vtkActor::New(); - anActor->SetMapper(aPresent->GetMapper()); - anActor->GetProperty()->SetRepresentation(VTK_WIREFRAME); - - theRenderer->AddActor(anActor); - anActor->Delete(); - - return 0; - } -}; +void PrintErr(){ + cout<<"***************************ERROR*****************************************"<BuildGroups(); - myConvertor->BuildFields(); - myConvertor->BuildMinMax(); - const VISU::TMeshMap& aMeshMap = myConvertor->GetMeshMap(); - VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - if(aMeshMapIter == aMeshMap.end()) - return 0; - - const std::string& aMeshName = aMeshMapIter->first; - const VISU::PMesh aMesh = aMeshMapIter->second; - const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; - - //Import fields - aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; - const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; - VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ - const VISU::PField aField = aFieldMapIter->second; - //if(aField->myNbComp == 1) - // continue; - const std::string& aFieldName = aFieldMapIter->first; - const VISU::TValField& aValField = aField->myValField; - VISU::TValField::const_reverse_iterator aValFieldIter = aValField.rbegin(); - if(aValFieldIter == aValField.rend()) - return 0; - - int aTimeStamp = aValFieldIter->first; - - VISU_ColoredPL* aPresent = NULL; - if(anEntity != VISU::NODE_ENTITY){ - aPresent = CreateColoredPL(myConvertor.get(), - aMeshName, - anEntity, - aFieldName, - aTimeStamp); - - }else{ - continue; - aPresent = CreateColoredPL(myConvertor.get(), - aMeshName, - anEntity, - aFieldName, - aTimeStamp); - } - - vtkActor* anActor = vtkActor::New(); - anActor->SetMapper(aPresent->GetMapper()); - - VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); - aScalarBar->SetLookupTable(aPresent->GetBarTable()); - - theRenderer->AddActor(anActor); - anActor->Delete(); - - theRenderer->AddActor2D(aScalarBar); - aScalarBar->Delete(); - } + try{ + if(argc == 1){ + PrintMissing(); + return 1; + } + if(argc == 2 && !strcmp(argv[1],"-h")) { + PrintHelp(); + return 1; } - return 0; - } -}; - - -//---------------------------------------------------------------------------- -struct TXLSSource -{ - VISU::TTableContainer myContainer; - - TXLSSource(char** argv) - { - VISU::ImportTables( argv[1], myContainer ); - } - - int Publish(vtkRenderer *theRenderer) const - { - if ( myContainer.empty() ) - return 0; - - VISU::PPolyDataIDMapper anIDMapper = myContainer[0]; - - VISU_DeformedGridPL* aPresent = VISU_DeformedGridPL::New(); - aPresent->SetPolyDataIDMapper(anIDMapper); - //aPresent->SetContourPrs( true ); - aPresent->Update(); - - vtkActor* anActor = vtkActor::New(); - anActor->SetMapper(aPresent->GetMapper()); - - theRenderer->AddActor(anActor); - anActor->Delete(); - VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); - aScalarBar->SetLookupTable(aPresent->GetBarTable()); + char* aFileName =0; + char* aMeshName =0; + char* aFieldName =0; + int aTimeStampNumber = 1; + int aComponentNumber = 0; + bool allInit = false; + bool isMeshOk = false; + bool isFieldOk = false; + bool isTimeStampOk = false; + bool isComponentOk = false; + + if(argc == 4 ){ + aFileName = new char[static_cast(strlen(argv[1])) + 1]; + aMeshName = new char[static_cast(strlen(argv[2])) + 1]; + aFieldName = new char[static_cast(strlen(argv[3])) + 1]; + + strcpy(aFileName,argv[1]); + strcpy(aMeshName,argv[2]); + strcpy(aFieldName,argv[3]); + + allInit = true; + } + + if(argc == 5) { + aFileName = new char[static_cast(strlen(argv[1])) + 1]; + aMeshName = new char[static_cast(strlen(argv[2])) + 1]; + aFieldName = new char[static_cast(strlen(argv[3])) + 1]; + + strcpy(aFileName,argv[1]); + strcpy(aMeshName,argv[2]); + strcpy(aFieldName,argv[3]); + + aTimeStampNumber = atoi(argv[4]); + allInit = true; + } - theRenderer->AddActor2D(aScalarBar); - aScalarBar->Delete(); + if(argc == 6) { + aFileName = new char[static_cast(strlen(argv[1])) + 1]; + aMeshName = new char[static_cast(strlen(argv[2])) + 1]; + aFieldName = new char[static_cast(strlen(argv[3])) + 1]; + + strcpy(aFileName,argv[1]); + strcpy(aMeshName,argv[2]); + strcpy(aFieldName,argv[3]); + + aTimeStampNumber = atoi(argv[4]); + aComponentNumber = atoi(argv[5]); + allInit = true; + } - return 0; - } -}; - -//---------------------------------------------------------------------------- -template -int RenderPresentation(const TPrsBuilder& thePrsBuilder) -{ - vtkRenderWindow *aWindow = vtkRenderWindow::New(); - vtkRenderer *aRenderer = vtkRenderer::New(); - - aWindow->AddRenderer(aRenderer); - aRenderer->GetActiveCamera()->ParallelProjectionOn(); - - vtkRenderWindowInteractor *anInteractor = vtkRenderWindowInteractor::New(); - anInteractor->SetRenderWindow(aWindow); - aWindow->Delete(); - - vtkInteractorStyle* aStyle = vtkInteractorStyleTrackballCamera::New(); - anInteractor->SetInteractorStyle(aStyle); - aStyle->Delete(); - - int aRet = thePrsBuilder.Publish(aRenderer); - - aWindow->Render(); - anInteractor->Start(); - - return aRet; -} - - -//---------------------------------------------------------------------------- -int -main(int argc, char** argv) -{ - try{ - if (argc > 1) { - QFileInfo aFileInfo( argv[1] ); - if ( aFileInfo.isFile() ) { - QString anExtension = aFileInfo.extension(); - if ( anExtension == "med" ) { - //TMeshBulder aBuilder( argv ); - TColoredPrsBulder aBuilder( argv ); - return RenderPresentation( aBuilder ); - } else if ( anExtension == "xls" || anExtension == "txt" ) - return RenderPresentation( TXLSSource( argv ) ); + if(allInit){ + + vtkRenderWindow *aWindow = vtkRenderWindow::New(); + vtkRenderer *aRenderer = vtkRenderer::New(); + + aWindow->AddRenderer(aRenderer); + aRenderer->GetActiveCamera()->ParallelProjectionOn(); + + vtkRenderWindowInteractor *anInteractor = vtkRenderWindowInteractor::New(); + anInteractor->SetRenderWindow(aWindow); + aWindow->Delete(); + + vtkInteractorStyle* aStyle = vtkInteractorStyleTrackballCamera::New(); + anInteractor->SetInteractorStyle(aStyle); + aStyle->Delete(); + + VISU_Convertor* aConvertor = CreateConvertor(aFileName); + aConvertor->BuildEntities(); + aConvertor->BuildGroups(); + aConvertor->BuildFields(); + aConvertor->BuildMinMax(); + const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap(); + VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + if(aMeshMapIter == aMeshMap.end()) return 0; + //Iterate by meshes + for (;aMeshMapIter != aMeshMap.end();aMeshMapIter++) { + + const std::string& theMeshName = aMeshMapIter->first; + if( strcmp(aMeshName, theMeshName.c_str()) ) + continue; + else + isMeshOk = true; + + const VISU::PMesh aMesh = aMeshMapIter->second; + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + //Iterate by meshes on entity + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; + + const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + + //Iterate by field + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + const VISU::PField aField = aFieldMapIter->second; + const std::string& theFieldName = aFieldMapIter->first; + + if( strcmp(aFieldName, theFieldName.c_str()) ) + continue; + else + isFieldOk = true; + + if(aComponentNumber > aField->myNbComp) + continue; + else + isComponentOk = true; + + const VISU::TValField& aValField = aField->myValField; + VISU::TValField::const_iterator aValFieldIter = 0; + aValFieldIter = aValField.find(aTimeStampNumber); + if(aValFieldIter == aValField.end()) + continue; + else + isTimeStampOk = true; + + int aTimeStamp = aValFieldIter->first; + + vtkActor* anActor = vtkActor::New(); + + if(anEntity != VISU::NODE_ENTITY){ + VISU::PUnstructuredGridIDMapper anUnstructuredGridIDMapper = + aConvertor->GetTimeStampOnMesh(theMeshName, + anEntity, + theFieldName, + aTimeStamp); + + VISU_ElnoGeometryFilter *aGeometryFilter = VISU_ElnoGeometryFilter::New(); + aGeometryFilter->SetScalarMode(aComponentNumber); + aGeometryFilter->SetInput( anUnstructuredGridIDMapper->GetUnstructuredGridOutput() ); + aGeometryFilter->Update(); + + VISU_OpenGLElnoMapper* aMapper = VISU_OpenGLElnoMapper::New(); + aMapper->SetInput( aGeometryFilter->GetOutput() ); + + + double* range = aGeometryFilter->GetRange(); + + VISU_LookupTable* aMapperTable( VISU_LookupTable::New() ); + aMapperTable->SetHueRange(0.667, 0.0); + aMapperTable->SetRange( aGeometryFilter->GetRange() ); + aMapperTable->Build(); + + + aMapper->SetLookupTable( aMapperTable ); + aMapper->SetUseLookupTableScalarRange( true ); + aMapper->SetColorModeToMapScalars(); + aMapper->ScalarVisibilityOn(); + + + anActor->SetMapper( aMapper ); + + VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); + aScalarBar->SetLookupTable( aMapperTable ); + + aRenderer->AddActor(anActor); + aRenderer->AddActor2D(aScalarBar); + }else{ + continue; + } + + aWindow->Render(); + aRenderer->ResetCamera(); + + anInteractor->Start(); + return 0; + } + } } } + else{ + PrintMissing(); + return 1; + } + + if(!isMeshOk) { + PrintErr(); + cout<<"Can not find mesh with name `"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkCxxRevisionMacro(VISU_ElnoGeometryFilter, "$Revision$"); +vtkStandardNewMacro(VISU_ElnoGeometryFilter); + + +//---------------------------------------------------------------------------------------------- +// Construct with all types of clipping turned off. +VISU_ElnoGeometryFilter::VISU_ElnoGeometryFilter() +{ + this->PointMinimum = 0; + this->PointMaximum = VTK_LARGE_ID; + + this->CellMinimum = 0; + this->CellMaximum = VTK_LARGE_ID; + + this->Extent[0] = -VTK_DOUBLE_MAX; + this->Extent[1] = VTK_DOUBLE_MAX; + this->Extent[2] = -VTK_DOUBLE_MAX; + this->Extent[3] = VTK_DOUBLE_MAX; + this->Extent[4] = -VTK_DOUBLE_MAX; + this->Extent[5] = VTK_DOUBLE_MAX; + + this->PointClipping = 0; + this->CellClipping = 0; + this->ExtentClipping = 0; + + this->Merging = 0; + this->Locator = NULL; + + myElnoData = NULL; + myElnoMapper = NULL; + myScalarMode = 0; + myMinMax[0] = 0.; + myMinMax[1] = 1.; +} +//---------------------------------------------------------------------------------------------- +VISU_ElnoGeometryFilter::~VISU_ElnoGeometryFilter() +{ + if ( this->Locator ) + { + this->Locator->UnRegister(this); + this->Locator = NULL; + } +} + +//---------------------------------------------------------------------------------------------- +int VISU_ElnoGeometryFilter::RequestData(vtkInformation *request, + vtkInformationVector **inputVector, + vtkInformationVector *outputVector) +{ + // get the info objects + vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + // get the input and ouptut + vtkDataSet *input = vtkDataSet::SafeDownCast( + inInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkPolyData *output = vtkPolyData::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT())); + + vtkIdType numCells=input->GetNumberOfCells(); + + if(!InitInternalArray(input)) + return 1; + + if (numCells == 0) + { + return 1; + } + + if (input->GetDataObjectType() == VTK_UNSTRUCTURED_GRID){ + this->UnstructuredGridExecute(input, output, outInfo); + return 1; + }else + return Superclass::RequestData(request,inputVector,outputVector); + + return 1; +} +//---------------------------------------------------------------------------------------------- +template +void CopyArray(TValueType *outputPtr, TValueType* inputPtr,const vtkIdType& theDataSize){ + for(vtkIdType iData =0;iData < theDataSize;iData++){ + *outputPtr = *inputPtr; + outputPtr++;inputPtr++; + } +} +//---------------------------------------------------------------------------------------------- +void VISU_ElnoGeometryFilter::UnstructuredGridExecute(vtkDataSet *dataSetInput, + vtkPolyData *output, + vtkInformation *outInfo) +{ + vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)dataSetInput; + vtkCellArray *Connectivity = input->GetCells(); + if (Connectivity == NULL) + { + return; + } + + //Create data array + vtkDataArray * aElnoScalars = vtkDataArray::CreateDataArray(myElnoData->GetDataType()); + + vtkIdType cellId; + int i; + int allVisible; + vtkIdType npts = 0; + vtkIdType *pts = 0; + vtkPoints *p = input->GetPoints(); + vtkIdType numCells=input->GetNumberOfCells(); + vtkPointData *pd = input->GetPointData(); + vtkCellData *cd = input->GetCellData(); + vtkPointData *outputPD = output->GetPointData(); + vtkCellData *outputCD = output->GetCellData(); + vtkCellArray *Verts, *Lines, *Polys, *Strips; + vtkIdList *cellIds, *faceIds; + char *cellVis; + vtkIdType newCellId; + int faceId, *faceVerts, numFacePts; + double x[3]; + int PixelConvert[4]; + // ghost cell stuff + unsigned char updateLevel = (unsigned char) + (outInfo->Get( + vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS())); + unsigned char *cellGhostLevels = 0; + + PixelConvert[0] = 0; + PixelConvert[1] = 1; + PixelConvert[2] = 3; + PixelConvert[3] = 2; + + vtkDebugMacro(<<"Executing geometry filter for unstructured grid input"); + + vtkDataArray* temp = 0; + if (cd) + { + temp = cd->GetArray("vtkGhostLevels"); + } + if ( (!temp) || (temp->GetDataType() != VTK_UNSIGNED_CHAR) + || (temp->GetNumberOfComponents() != 1)) + { + vtkDebugMacro("No appropriate ghost levels field available."); + } + else + { + cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0); + } + + // Check input + if ( Connectivity == NULL ) + { + vtkDebugMacro(<<"Nothing to extract"); + return; + } + + // Determine nature of what we have to do + cellIds = vtkIdList::New(); + faceIds = vtkIdList::New(); + if ( (!this->CellClipping) && (!this->PointClipping) && + (!this->ExtentClipping) ) + { + allVisible = 1; + cellVis = NULL; + } + else + { + allVisible = 0; + cellVis = new char[numCells]; + } + + // Just pass points through, never merge + output->SetPoints(input->GetPoints()); + outputPD->PassData(pd); + + outputCD->CopyAllocate(cd,numCells,numCells/2); + + Verts = vtkCellArray::New(); + Verts->Allocate(numCells/4+1,numCells); + Lines = vtkCellArray::New(); + Lines->Allocate(numCells/4+1,numCells); + Polys = vtkCellArray::New(); + Polys->Allocate(numCells/4+1,numCells); + Strips = vtkCellArray::New(); + Strips->Allocate(numCells/4+1,numCells); + + // Loop over the cells determining what's visible + if (!allVisible) + { + for (cellId=0, Connectivity->InitTraversal(); + Connectivity->GetNextCell(npts,pts); + cellId++) + { + cellVis[cellId] = 1; + if ( this->CellClipping && cellId < this->CellMinimum || + cellId > this->CellMaximum ) + { + cellVis[cellId] = 0; + } + else + { + for (i=0; i < npts; i++) + { + p->GetPoint(pts[i], x); + if ( (this->PointClipping && (pts[i] < this->PointMinimum || + pts[i] > this->PointMaximum) ) || + (this->ExtentClipping && + (x[0] < this->Extent[0] || x[0] > this->Extent[1] || + x[1] < this->Extent[2] || x[1] > this->Extent[3] || + x[2] < this->Extent[4] || x[2] > this->Extent[5] )) ) + { + cellVis[cellId] = 0; + break; + }//point/extent clipping + }//for each point + }//if point clipping needs checking + }//for all cells + }//if not all visible + + // Loop over all cells now that visibility is known + // (Have to compute visibility first for 3D cell boundarys) + int progressInterval = numCells/20 + 1; + + vtkDataArray *aTmpElnoComponents = vtkDataArray::CreateDataArray(myElnoData->GetDataType()); + aTmpElnoComponents->SetNumberOfComponents(1); + + + vtkDataArray *aTmpElnoScalars = vtkDataArray::CreateDataArray(myElnoData->GetDataType()); + aTmpElnoScalars->SetNumberOfComponents(1); + vtkIdType aPosition = 0; + + for (cellId=0, Connectivity->InitTraversal(); + Connectivity->GetNextCell(npts,pts); + cellId++) + { + //Progress and abort method support + if ( !(cellId % progressInterval) ) + { + vtkDebugMacro(<<"Process cell #" << cellId); + this->UpdateProgress ((double)cellId/numCells); + } + + // Handle ghost cells here. Another option was used cellVis array. + if (cellGhostLevels && cellGhostLevels[cellId] > updateLevel) + { // Do not create surfaces in outer ghost cells. + continue; + } + + if (allVisible || cellVis[cellId]) //now if visible extract geometry + { + //special code for nonlinear cells - rarely occurs, so right now it + //is slow. + //Create temporary data array + vtkDataArray *aComponents = vtkDataArray::CreateDataArray(myElnoData->GetDataType()); + aComponents->SetNumberOfComponents(2); + switch (input->GetCellType(cellId)) + { + case VTK_EMPTY_CELL: + break; + + case VTK_VERTEX: + case VTK_POLY_VERTEX: + newCellId = Verts->InsertNextCell(npts,pts); + outputCD->CopyData(cd,cellId,newCellId); + break; + + case VTK_LINE: + case VTK_POLY_LINE: + newCellId = Lines->InsertNextCell(npts,pts); + outputCD->CopyData(cd,cellId,newCellId); + break; + + //-- + case VTK_TRIANGLE: + case VTK_QUAD: + case VTK_POLYGON: + newCellId = Polys->InsertNextCell(npts,pts); + outputCD->CopyData(cd,cellId,newCellId); + + //Copy Elno Data + this->GetElementData(cellId, aComponents); + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition); + break; + + case VTK_TRIANGLE_STRIP: + newCellId = Strips->InsertNextCell(npts,pts); + outputCD->CopyData(cd,cellId,newCellId); + break; + + case VTK_PIXEL: + //Get Elno Data + GetElementData(cellId, aComponents); + + newCellId = Polys->InsertNextCell(npts); + for ( i=0; i < npts; i++) + { + Polys->InsertCellPoint(pts[PixelConvert[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,PixelConvert[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + break; + + case VTK_TETRA: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 4; faceId++) + { + faceIds->Reset(); + faceVerts = vtkTetra::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + numFacePts = 3; + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_VOXEL: + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 6; faceId++) + { + faceIds->Reset(); + faceVerts = vtkVoxel::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[PixelConvert[i]]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[PixelConvert[i]]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_HEXAHEDRON: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 6; faceId++) + { + faceIds->Reset(); + faceVerts = vtkHexahedron::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_WEDGE: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 5; faceId++) + { + faceIds->Reset(); + faceVerts = vtkWedge::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + numFacePts = 3; + if (faceVerts[3] >= 0) + { + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + } + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_PYRAMID: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 5; faceId++) + { + faceIds->Reset(); + faceVerts = vtkPyramid::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + numFacePts = 3; + if (faceVerts[3] >= 0) + { + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + } + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_PENTAGONAL_PRISM: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 7; faceId++) + { + faceIds->Reset(); + faceVerts = vtkPentagonalPrism::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + if (faceVerts[4] >= 0) + { + faceIds->InsertNextId(pts[faceVerts[4]]); + numFacePts = 5; + } + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + case VTK_HEXAGONAL_PRISM: + //Get Elno Data + GetElementData(cellId, aComponents); + for (faceId = 0; faceId < 8; faceId++) + { + faceIds->Reset(); + faceVerts = vtkHexagonalPrism::GetFaceArray(faceId); + faceIds->InsertNextId(pts[faceVerts[0]]); + faceIds->InsertNextId(pts[faceVerts[1]]); + faceIds->InsertNextId(pts[faceVerts[2]]); + faceIds->InsertNextId(pts[faceVerts[3]]); + numFacePts = 4; + if (faceVerts[4] >= 0) + { + faceIds->InsertNextId(pts[faceVerts[4]]); + faceIds->InsertNextId(pts[faceVerts[5]]); + numFacePts = 6; + } + input->GetCellNeighbors(cellId, faceIds, cellIds); + if ( cellIds->GetNumberOfIds() <= 0 || + (!allVisible && !cellVis[cellIds->GetId(0)]) ) + { + newCellId = Polys->InsertNextCell(numFacePts); + for ( i=0; i < numFacePts; i++) + { + Polys->InsertCellPoint(pts[faceVerts[i]]); + //Copy Elno Data + this->CopyElementData(aTmpElnoComponents,aTmpElnoScalars,aComponents,aPosition,faceVerts[i]); + } + outputCD->CopyData(cd,cellId,newCellId); + } + } + break; + + //Quadratic cells + case VTK_QUADRATIC_EDGE: + case VTK_QUADRATIC_TRIANGLE: + case VTK_QUADRATIC_QUAD: + case VTK_QUADRATIC_TETRA: + case VTK_QUADRATIC_HEXAHEDRON: + case VTK_QUADRATIC_WEDGE: + case VTK_QUADRATIC_PYRAMID: + { + vtkGenericCell *cell = vtkGenericCell::New(); + input->GetCell(cellId,cell); + vtkIdList *ipts = vtkIdList::New(); + vtkPoints *coords = vtkPoints::New(); + vtkIdList *icellIds = vtkIdList::New(); + vtkIdType inewCellId; + + if ( cell->GetCellDimension() == 1 ) + { + cell->Triangulate(0,ipts,coords); + for (i=0; i < ipts->GetNumberOfIds(); i+=2) + { + inewCellId = Lines->InsertNextCell(2); + Lines->InsertCellPoint(ipts->GetId(i)); + Lines->InsertCellPoint(ipts->GetId(i+1)); + outputCD->CopyData(cd,cellId,inewCellId); + } + } + else if ( cell->GetCellDimension() == 2 ) + { + cell->Triangulate(0,ipts,coords); + for (i=0; i < ipts->GetNumberOfIds(); i+=3) + { + inewCellId = Polys->InsertNextCell(3); + Polys->InsertCellPoint(ipts->GetId(i)); + Polys->InsertCellPoint(ipts->GetId(i+1)); + Polys->InsertCellPoint(ipts->GetId(i+2)); + outputCD->CopyData(cd,cellId,inewCellId); + } + } + else //3D nonlinear cell + { + vtkCell *face; + for (int j=0; j < cell->GetNumberOfFaces(); j++) + { + face = cell->GetFace(j); + input->GetCellNeighbors(cellId, face->PointIds, icellIds); + if ( icellIds->GetNumberOfIds() <= 0) + { + face->Triangulate(0,ipts,coords); + for (i=0; i < ipts->GetNumberOfIds(); i+=3) + { + inewCellId = Polys->InsertNextCell(3); + Polys->InsertCellPoint(ipts->GetId(i)); + Polys->InsertCellPoint(ipts->GetId(i+1)); + Polys->InsertCellPoint(ipts->GetId(i+2)); + outputCD->CopyData(cd,cellId,inewCellId); + } + } + } + } //3d cell + icellIds->Delete(); + coords->Delete(); + ipts->Delete(); + cell->Delete(); + } + break; //done with quadratic cells + + } //switch + aComponents->Delete(); + } //if visible + } //for all cells + + // Update ourselves and release memory + // + output->SetVerts(Verts); + Verts->Delete(); + output->SetLines(Lines); + Lines->Delete(); + output->SetPolys(Polys); + Polys->Delete(); + output->SetStrips(Strips); + Strips->Delete(); + + + myMinMax[0] = *(aTmpElnoScalars->GetTuple(0)); + myMinMax[1] = *(aTmpElnoScalars->GetTuple(0)); + + //Build Min and Max + for(vtkIdType count = 0;count < aTmpElnoScalars->GetSize();count++){ + double s = *(aTmpElnoScalars->GetTuple(count)); + if(s < myMinMax[0]){ + myMinMax[0] = s; + } + else if(s > myMinMax[1]) + { + myMinMax[1] = s; + } + } + + vtkIdType aNbEffectiveComponents = (aTmpElnoScalars->GetSize()/output->GetNumberOfCells())+1; + + vtkDataArray *aElnoPseudoScalars = vtkDataArray::CreateDataArray(this->myElnoData->GetDataType()); + aElnoPseudoScalars->SetName("ELNO_PSEUDO_SCALARS"); + aElnoPseudoScalars->SetNumberOfTuples(aTmpElnoComponents->GetSize()); + aElnoPseudoScalars->SetNumberOfComponents(1); + + + switch(this->myElnoData->GetDataType()){ + + vtkTemplateMacro3(CopyArray, + static_cast(aElnoPseudoScalars->GetVoidPointer(0)), + static_cast(aTmpElnoScalars->GetVoidPointer(0)), + aTmpElnoScalars->GetSize()); + default: + break; + } + + output->GetCellData()->AddArray(aElnoPseudoScalars); + output->Squeeze(); + + aElnoPseudoScalars->Delete(); + + aTmpElnoComponents->Delete(); + + vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points," + << output->GetNumberOfCells() << " cells."); + cellIds->Delete(); + faceIds->Delete(); + if ( cellVis ) + { + delete [] cellVis; + } +} + +//---------------------------------------------------------------------------------------------- +void VISU_ElnoGeometryFilter::SetScalarMode(vtkIdType theScalarMode){ + if(myScalarMode == theScalarMode) + return; + myScalarMode = theScalarMode; +} + +//---------------------------------------------------------------------------------------------- +vtkIdType VISU_ElnoGeometryFilter::GetScalarMode() const{ + return myScalarMode; +} + +//---------------------------------------------------------------------------------------------- +double* VISU_ElnoGeometryFilter::GetRange(){ + return myMinMax; +} + +//---------------------------------------------------------------------------------------------- +bool VISU_ElnoGeometryFilter::InitInternalArray(vtkDataSet *input){ + + if (!VISU::IsDataOnElnoCells(input)) + return false; + myElnoData = input->GetCellData()->GetArray("ELNO_FIELD"); + myElnoMapper = input->GetCellData()->GetArray("ELNO_COMPONENT_MAPPER"); + return true; +} + + +//---------------------------------------------------------------------------------------------- +template +void +GetElementDataByModulus(TValueType* theInputPtr, + TValueType* theOutputPtr, + const vtkIdType& theDataSize, + const vtkIdType& theNbComponent ) +{ + vtkFloatingPointType aScalar; + for(vtkIdType iData = 0; iData < theDataSize; iData++){ + aScalar = 0; + for(vtkIdType iComponent=0; iComponent < theNbComponent; iComponent++){ + aScalar += (*(theInputPtr+iComponent))*(*(theInputPtr+iComponent)); + } + *theOutputPtr = TValueType(sqrt(aScalar)); + theOutputPtr++; + theInputPtr += theNbComponent; + } +} + +//---------------------------------------------------------------------------------------------- +template +void GetElementDataByComponent(TValueType* theInputPtr, + TValueType* theOutputPtr, + const vtkIdType& theComponentId, + const vtkIdType& theDataSize, + const vtkIdType& theNbComponent){ + for(vtkIdType iValue = 0; iValue < theDataSize; iValue++){ + *theOutputPtr = *(theInputPtr + theComponentId); + theInputPtr+=theNbComponent; + theOutputPtr++; + } +} + +//---------------------------------------------------------------------------------------------- + +template +void CopyArray1(TValueType *theInputPtr, + TValueType *theOutPtr, + const vtkIdType& theDataSize, + const vtkIdType& theNbComponent) +{ + for(vtkIdType iData = 0; iData < theDataSize; iData++){ + for(vtkIdType iComponent=0; iComponent < theNbComponent;iComponent++){ + *theOutPtr++ = *theInputPtr++; + } + } +} + +//---------------------------------------------------------------------------------------------- +void VISU_ElnoGeometryFilter::GetElementData(const vtkIdType& theElemId, + vtkDataArray* theOutArray){ + if(myElnoMapper){ + int aElemInfo[3]; + vtkIntArray *anArray = vtkIntArray::SafeDownCast(myElnoMapper); + anArray->GetTupleValue(theElemId,aElemInfo); + vtkIdType aDataSize = aElemInfo[2]; + vtkIdType aNbComponent = aElemInfo[1]; + vtkIdType aStartId = aElemInfo[0]; + theOutArray->SetNumberOfComponents(aNbComponent); + theOutArray->SetNumberOfTuples(aDataSize); + void *aInputPtr = myElnoData->GetVoidPointer(aStartId); + void *aOutputPtr = theOutArray->GetVoidPointer(0); + + switch(myElnoData->GetDataType()){ + vtkTemplateMacro4(CopyArray1, + static_cast(aInputPtr), + static_cast(aOutputPtr), + aDataSize, + aNbComponent); + default: + break; + } + } + else { + theOutArray->SetNumberOfTuples(0); + theOutArray->SetNumberOfComponents(0); + } +} + +//---------------------------------------------------------------------------------------------- +/*! + Copy Elno Element (or) point data +*/ + +void +VISU_ElnoGeometryFilter::CopyElementData(vtkDataArray *toComponents, + vtkDataArray *toScalars, + vtkDataArray *from, + vtkIdType& position, + const vtkIdType& PntId) const +{ + //Optimize needed + vtkIdType aNbComponents = from->GetNumberOfComponents(); + + vtkDataArray *tmpComponents = vtkDataArray::CreateDataArray(this->myElnoData->GetDataType()); + tmpComponents->SetNumberOfTuples(toComponents->GetNumberOfTuples()); + tmpComponents->DeepCopy(toComponents); + + vtkDataArray *tmpScalars = vtkDataArray::CreateDataArray(this->myElnoData->GetDataType()); + tmpScalars->SetNumberOfTuples(toScalars->GetNumberOfTuples()); + tmpScalars->DeepCopy(toScalars); + + vtkIdType aDataSize = 0; + void *inputPtr = NULL; + + + if(PntId == -2){ + aDataSize = from->GetNumberOfTuples(); + inputPtr = from->GetVoidPointer(0); + } + else{ + aDataSize = 1; + inputPtr = from->GetVoidPointer(PntId*aNbComponents); + } + + toComponents->Allocate(position*aNbComponents + aDataSize*aNbComponents); + toScalars->Allocate(position+aDataSize); + + switch(this->myElnoData->GetDataType()){ + vtkTemplateMacro4(CopyArray1, + static_cast(tmpComponents->GetVoidPointer(0)), + static_cast(toComponents->GetVoidPointer(0)), + position*aNbComponents, + 1); + default: + break; + } + + switch(this->myElnoData->GetDataType()){ + vtkTemplateMacro4(CopyArray1, + static_cast(tmpScalars->GetVoidPointer(0)), + static_cast(toScalars->GetVoidPointer(0)), + position, + 1); + default: + break; + } + + //Optimize needed + + //Fill Elno Field + void *outputComponentsPtr = toComponents->GetVoidPointer(position*aNbComponents); + switch(this->myElnoData->GetDataType()){ + vtkTemplateMacro4(CopyArray1, + static_cast(inputPtr), + static_cast(outputComponentsPtr), + aDataSize, + aNbComponents); + default: + break; + } + + + + //Fill Scalars array + void *outputScalarasPtr = toScalars->GetVoidPointer(position); + if( !myScalarMode ) { + switch(this->myElnoData->GetDataType()){ + vtkTemplateMacro4(GetElementDataByModulus, + static_cast(inputPtr), + static_cast(outputScalarasPtr), + aDataSize, + aNbComponents); + default: + break; + } + } + else{ + switch(this->myElnoData->GetDataType()){ + vtkTemplateMacro5(GetElementDataByComponent, + static_cast(inputPtr), + static_cast(outputScalarasPtr), + myScalarMode - 1, + aDataSize, + aNbComponents); + default: + break; + } + } + position+=aDataSize; + tmpComponents->Delete(); + tmpScalars->Delete(); +} + +//---------------------------------------------------------------------------------------------- +vtkIdType VISU_ElnoGeometryFilter::GetNbOfEffectiveElnoComponents(vtkCellData *theInputData){ + vtkIdType nbEffectiveComponents = -1; + vtkDataArray* aFieldArray = theInputData->GetArray("ELNO_FIELD"); + if(aFieldArray){ + nbEffectiveComponents = aFieldArray->GetNumberOfComponents(); + } + return nbEffectiveComponents; +} +//---------------------------------------------------------------------------------------------- +int VISU_ElnoGeometryFilter::GetNbOfElnoComponents(vtkCellData *theInputData) { + vtkIdType nbComponents = -1; + vtkDataArray* aFieldArray = theInputData->GetArray("ELNO_COMPONENT_MAPPER"); + if(aFieldArray){ + vtkIntArray *aInfoArray = vtkIntArray::SafeDownCast(aFieldArray); + int aInfo[3]; + aInfoArray->GetTupleValue(0,aInfo); + nbComponents = aInfo[1]; + } + return nbComponents; +} +//---------------------------------------------------------------------------------------------- +vtkIdType VISU_ElnoGeometryFilter::GetNbOfElnoTuples(vtkCellData *theInputData) { + int nbTuples = 0; + vtkDataArray* aFieldArray = theInputData->GetArray("ELNO_COMPONENT_MAPPER"); + if(aFieldArray){ + vtkIntArray *aInfoArray = vtkIntArray::SafeDownCast(aFieldArray); + vtkIdType nbInfoTyples = aInfoArray->GetNumberOfTuples(); + int aInfo[3]; + for( vtkIdType iTuple = 0;iTuple < nbInfoTyples; iTuple++ ){ + aInfoArray->GetTupleValue(iTuple,aInfo); + nbTuples+=aInfo[2]; + } + return nbTuples; + } + else + return -1; +} +//---------------------------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_ElnoGeometryFilter.hxx b/src/PIPELINE/VISU_ElnoGeometryFilter.hxx new file mode 100755 index 00000000..11758399 --- /dev/null +++ b/src/PIPELINE/VISU_ElnoGeometryFilter.hxx @@ -0,0 +1,55 @@ + +#ifndef VISU_ElnoGeometryFilter_HeaderFile +#define VISU_ElnoGeometryFilter_HeaderFile + +#include + +class VISU_ElnoGeometryFilter : public vtkGeometryFilter { +public: + + static VISU_ElnoGeometryFilter *New(); + + static vtkIdType GetNbOfElnoComponents(vtkCellData *); + + static vtkIdType GetNbOfEffectiveElnoComponents(vtkCellData *); + + static vtkIdType GetNbOfElnoTuples(vtkCellData *); + + static void PrintElemData(vtkDataArray *arr); + + vtkTypeRevisionMacro(vtkGeometryFilter,vtkPolyDataAlgorithm); + + void SetScalarMode(vtkIdType theScalarMode = 0); + vtkIdType GetScalarMode() const; + double* GetRange(); + +protected: + + VISU_ElnoGeometryFilter(); + + ~VISU_ElnoGeometryFilter(); + + virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + + + void UnstructuredGridExecute (vtkDataSet *, vtkPolyData *, vtkInformation *); + void GetElementData(const vtkIdType& theElemId, vtkDataArray *theOutArray); + + +private: + bool InitInternalArray(vtkDataSet *input); + void CopyElementData(vtkDataArray *toComponents, //Components + vtkDataArray *toScalars, //Scalars + vtkDataArray *from, + vtkIdType& position, + const vtkIdType& PntId = -2 ) const; + +private: + double myMinMax[2]; // myMinMax[0] - Min + // myMinMax[1] - Max + vtkDataArray *myElnoData; + vtkDataArray *myElnoMapper; + vtkIdType myScalarMode; +}; + +#endif diff --git a/src/PIPELINE/VISU_OpenGLElnoMapper.cxx b/src/PIPELINE/VISU_OpenGLElnoMapper.cxx new file mode 100755 index 00000000..ea210ae9 --- /dev/null +++ b/src/PIPELINE/VISU_OpenGLElnoMapper.cxx @@ -0,0 +1,2075 @@ +#include "VISU_OpenGLElnoMapper.hxx" + +#include "vtkCellArray.h" +#include "vtkCellData.h" +#include "vtkCommand.h" +#include "vtkDataArray.h" +#include "vtkFloatArray.h" +#include "vtkMatrix4x4.h" +#include "vtkObjectFactory.h" +#include "vtkOpenGLRenderer.h" +#include "vtkPlane.h" +#include "vtkPlaneCollection.h" +#include "vtkPointData.h" +#include "vtkPolyData.h" +#include "vtkPolygon.h" +#include "vtkProperty.h" +#include "vtkTimerLog.h" +#include "vtkTriangle.h" +#include "vtkOpenGLRenderWindow.h" +#include "vtkOpenGLTexture.h" +#include "vtkImageData.h" +#include "vtkCellData.h" +#include "vtkLookupTable.h" +#include "vtkObjectFactory.h" + +#ifndef VTK_IMPLEMENT_MESA_CXX +# include "vtkOpenGL.h" +#endif + +#include + + +#ifndef VTK_IMPLEMENT_MESA_CXX +vtkCxxRevisionMacro(VISU_OpenGLElnoMapper, "$Revision$"); +vtkStandardNewMacro(VISU_OpenGLElnoMapper); +#endif + +// some definitions for what the polydata has in it +#define VTK_PDM_NORMALS 0x01 +#define VTK_PDM_COLORS 0x02 +#define VTK_PDM_TCOORDS 0x04 +#define VTK_PDM_CELL_COLORS 0x08 +#define VTK_PDM_CELL_NORMALS 0x10 +#define VTK_PDM_POINT_TYPE_FLOAT 0x20 +#define VTK_PDM_POINT_TYPE_DOUBLE 0x40 +#define VTK_PDM_NORMAL_TYPE_FLOAT 0x80 +#define VTK_PDM_NORMAL_TYPE_DOUBLE 0x100 +#define VTK_PDM_TCOORD_TYPE_FLOAT 0x200 +#define VTK_PDM_TCOORD_TYPE_DOUBLE 0x400 +#define VTK_PDM_TCOORD_1D 0x800 +#define VTK_PDM_OPAQUE_COLORS 0x1000 +#define VTK_PDM_USE_FIELD_DATA 0x2000 + + + +// Construct empty object. +VISU_OpenGLElnoMapper::VISU_OpenGLElnoMapper() +{ + this->ListId = 0; + this->TotalCells = 0; + this->InternalColorTexture = 0; +} + +// Destructor (don't call ReleaseGraphicsResources() since it is virtual +VISU_OpenGLElnoMapper::~VISU_OpenGLElnoMapper() +{ + if (this->LastWindow) + { + this->ReleaseGraphicsResources(this->LastWindow); + } + if (this->InternalColorTexture) + { // Resources released previously. + this->InternalColorTexture->Delete(); + this->InternalColorTexture = 0; + } +} + +// Release the graphics resources used by this mapper. In this case, release +// the display list if any. +void VISU_OpenGLElnoMapper::ReleaseGraphicsResources(vtkWindow *win) +{ + if (this->ListId && win) + { + win->MakeCurrent(); + glDeleteLists(this->ListId,1); + this->ListId = 0; + } + this->LastWindow = NULL; + // We may not want to do this here. + if (this->InternalColorTexture) + { + this->InternalColorTexture->ReleaseGraphicsResources(win); + } +} + +// +// Receives from Actor -> maps data to primitives +// +void VISU_OpenGLElnoMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) +{ + vtkPolyData *input= this->GetInput(); + vtkPlaneCollection *clipPlanes; + vtkPlane *plane; + int i, numClipPlanes; + double planeEquation[4]; + + // + // 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); + if (!this->Static) + { + input->Update(); + } + this->InvokeEvent(vtkCommand::EndEvent,NULL); + + vtkIdType numPts = input->GetNumberOfPoints(); + if (numPts == 0) + { + vtkDebugMacro(<< "No points!"); + return; + } + } + + if ( this->LookupTable == NULL ) + { + this->CreateDefaultLookupTable(); + } + + // make sure our window is current + ren->GetRenderWindow()->MakeCurrent(); + + clipPlanes = this->ClippingPlanes; + + if (clipPlanes == NULL) + { + numClipPlanes = 0; + } + else + { + numClipPlanes = clipPlanes->GetNumberOfItems(); + if (numClipPlanes > 6) + { + vtkErrorMacro(<< "OpenGL guarantees at most 6 additional clipping planes"); + } + } + + for (i = 0; i < numClipPlanes; i++) + { + glEnable((GLenum)(GL_CLIP_PLANE0+i)); + } + + if ( clipPlanes ) + { + vtkMatrix4x4 *actorMatrix = vtkMatrix4x4::New(); + act->GetMatrix( actorMatrix ); + actorMatrix->Invert(); + + double origin[4], normal[3], point[4]; + + for (i = 0; i < numClipPlanes; i++) + { + plane = (vtkPlane *)clipPlanes->GetItemAsObject(i); + + plane->GetOrigin(origin); + plane->GetNormal(normal); + + point[0] = origin[0] + normal[0]; + point[1] = origin[1] + normal[1]; + point[2] = origin[2] + normal[2]; + + origin[3] = point[3] = 1.0; + + actorMatrix->MultiplyPoint( origin, origin ); + actorMatrix->MultiplyPoint( point, point ); + + if ( origin[3] != 1.0 ) + { + origin[0] /= origin[3]; + origin[1] /= origin[3]; + origin[2] /= origin[3]; + } + + if ( point[3] != 1.0 ) + { + point[0] /= point[3]; + point[1] /= point[3]; + point[2] /= point[3]; + } + + normal[0] = point[0] - origin[0]; + normal[1] = point[1] - origin[1]; + normal[2] = point[2] - origin[2]; + + planeEquation[0] = normal[0]; + planeEquation[1] = normal[1]; + planeEquation[2] = normal[2]; + planeEquation[3] = -(planeEquation[0]*origin[0]+ + planeEquation[1]*origin[1]+ + planeEquation[2]*origin[2]); + glClipPlane((GLenum)(GL_CLIP_PLANE0+i),planeEquation); + } + + actorMatrix->Delete(); + } + + // For vertex coloring, this sets this->Colors as side effect. + // For texture map coloring, this sets ColorCoordinates + // and ColorTextureMap as a side effect. + // I moved this out of the conditional because it is fast. + // Color arrays are cached. If nothing has changed, + // then the scalars do not have to be regenerted. + this->MapScalars(act->GetProperty()->GetOpacity()); + // If we are coloring by texture, then load the texture map. + if (this->ColorTextureMap) + { + if (this->InternalColorTexture == 0) + { + this->InternalColorTexture = vtkOpenGLTexture::New(); + this->InternalColorTexture->RepeatOff(); + } + this->InternalColorTexture->SetInput(this->ColorTextureMap); + // Keep color from interacting with texture. + float info[4]; + info[0] = info[1] = info[2] = info[3] = 1.0; + glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, info ); + } + + // + // 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) + { + if (!this->ImmediateModeRendering && + !this->GetGlobalImmediateModeRendering()) + { + this->ReleaseGraphicsResources(ren->GetRenderWindow()); + this->LastWindow = ren->GetRenderWindow(); + + // If we are coloring by texture, then load the texture map. + // Use Map as indicator, because texture hangs around. + if (this->ColorTextureMap) + { + this->InternalColorTexture->Load(ren); + } + + // 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()) + { + // If we are coloring by texture, then load the texture map. + // Use Map as indicator, because texture hangs around. + if (this->ColorTextureMap) + { + this->InternalColorTexture->Load(ren); + } + + // 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()) + { + // If we are coloring by texture, then load the texture map. + // Use Map as indicator, because texture hangs around. + if (this->ColorTextureMap) + { + this->InternalColorTexture->Load(ren); + } + // 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; + } + + for (i = 0; i < numClipPlanes; i++) + { + glDisable((GLenum)(GL_CLIP_PLANE0+i)); + } +} + + +// +// Helper routine which starts a poly, triangle or quad based upon +// the number of points in the polygon and whether triangles or quads +// were the last thing being drawn (we can get better performance if we +// can draw several triangles within a single glBegin(GL_TRIANGLES) or +// several quads within a single glBegin(GL_QUADS). +// +static void vtkOpenGLBeginPolyTriangleOrQuad(GLenum aGlFunction, + GLenum &previousGlFunction, + int npts) +{ + if (aGlFunction == GL_POLYGON) + { + switch (npts) + { + case 3: // Need to draw a triangle. + if (previousGlFunction != GL_TRIANGLES) + { + // we were not already drawing triangles, were we drawing quads? + if (previousGlFunction == GL_QUADS) + { + // we were previously drawing quads, close down the quads. + glEnd(); + } + // start drawing triangles + previousGlFunction = GL_TRIANGLES; + glBegin(GL_TRIANGLES); + } + break; + case 4: // Need to draw a quad + if (previousGlFunction != GL_QUADS) + { + // we were not already drawing quads, were we drawing triangles? + if (previousGlFunction == GL_TRIANGLES) + { + // we were previously drawing triangles, close down the triangles. + glEnd(); + } + // start drawing quads + previousGlFunction = GL_QUADS; + glBegin(GL_QUADS); + } + break; + default: + // if we were supposed to be drawing polygons but were really + // drawing triangles or quads, then we need to close down the + // triangles or quads and begin a polygon + if (previousGlFunction != GL_INVALID_VALUE + && previousGlFunction != GL_POLYGON) + { + glEnd(); + } + previousGlFunction = GL_POLYGON; + glBegin(aGlFunction); + break; + } + } + else if (aGlFunction == GL_POINTS) + { + // we are supposed to be drawing points + if (previousGlFunction != GL_POINTS) + { + // We were not drawing points before this, switch to points. + // We don't need to worry about switching from triangles or quads + // since draw all points before drawing any polygons (i.e. in the polys + // case we switch to triangles and quads as an optimization, there is + // nothing to switch to that is below points). + previousGlFunction = GL_POINTS; + glBegin(GL_POINTS); + } + } + else + { + previousGlFunction = aGlFunction; + glBegin(aGlFunction); + } +} + + +#define vtkDrawPointsMacro(ptype,ntype,glVertFuncs,glInitFuncs) \ +{ \ + vtkIdType nPts; unsigned short count = 0; \ + ptype *points = (ptype *)voidPoints; \ + glInitFuncs \ + glBegin(GL_POINTS); \ + while (ptIds < endPtIds) \ + { \ + nPts = *ptIds; \ + ++ptIds; \ + while (nPts > 0) \ + { \ + glVertFuncs \ + ++ptIds; \ + --nPts; \ + } \ + if (++count == 10000) \ + { \ + cellNum += 10000; \ + count = 0; \ + this->UpdateProgress((double)cellNum/this->TotalCells); \ + if (ren->GetRenderWindow()->CheckAbortStatus()) \ + { \ + noAbort = 0; \ + break; \ + } \ + } \ + } \ + cellNum += count; \ + glEnd(); \ +} + +#define vtkDrawPrimsMacro(ptype,ntype,prim,glVertFuncs,glInitFuncs) \ +{ \ + vtkIdType nPts; unsigned short count = 0; \ + ptype *points = (ptype *)voidPoints; \ + glInitFuncs \ + while (ptIds < endPtIds) \ + { \ + nPts = *ptIds; \ + ++ptIds; \ + glBegin(prim); \ + while (nPts > 0) \ + { \ + glVertFuncs \ + ++ptIds; \ + --nPts; \ + } \ + glEnd(); \ + if (++count == 10000) \ + { \ + cellNum += 10000; \ + count = 0; \ + this->UpdateProgress((double)cellNum/this->TotalCells); \ + if (ren->GetRenderWindow()->CheckAbortStatus()) \ + { \ + noAbort = 0; \ + break; \ + } \ + } \ + } \ + cellNum += count; \ +} + +#define vtkDrawPolysMacro(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \ +{ \ + vtkIdType nPts; unsigned short count = 0; \ + ptype *points = (ptype *)voidPoints; \ + GLenum previousGlFunction=GL_INVALID_VALUE; \ + glInitFuncs \ + while (ptIds < endPtIds) \ + { \ + nPts = *ptIds; \ + ++ptIds; \ + vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, nPts ); \ + glCellFuncs \ + while (nPts > 0) \ + { \ + glVertFuncs \ + ++ptIds; \ + --nPts; \ + } \ + if (++count == 10000) \ + { \ + cellNum += 10000; \ + count = 0; \ + this->UpdateProgress((double)cellNum/this->TotalCells); \ + if (ren->GetRenderWindow()->CheckAbortStatus()) \ + { \ + noAbort = 0; \ + break; \ + } \ + } \ + if ((previousGlFunction != GL_TRIANGLES) \ + && (previousGlFunction != GL_QUADS) \ + && (previousGlFunction != GL_POINTS)) \ + { \ + glEnd(); \ + } \ + } \ + cellNum += count; \ + if ((previousGlFunction == GL_TRIANGLES) \ + || (previousGlFunction == GL_QUADS) \ + || (previousGlFunction == GL_POINTS)) \ + { \ + glEnd(); \ + } \ +} + +#define vtkDrawStripLinesMacro(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \ +{ \ + vtkIdType nPts; \ + ptype *points = (ptype *)voidPoints; \ + vtkIdType *savedPtIds = ptIds; \ + glInitFuncs \ + while (ptIds < endPtIds) \ + { \ + glBegin(prim); \ + nPts = *ptIds; \ + ++ptIds; \ + glCellFuncs \ + while (nPts > 0) \ + { \ + glVertFuncs \ + ptIds += 2; \ + nPts -= 2; \ + } \ + glEnd(); \ + ptIds += nPts; /* nPts could be 0 or -1 here */ \ + } \ + ptIds = savedPtIds; \ + while (ptIds < endPtIds) \ + { \ + glBegin(prim); \ + nPts = *ptIds; \ + ++ptIds; \ + glCellFuncs \ + ++ptIds; \ + --nPts; \ + while (nPts > 0) \ + { \ + glVertFuncs \ + ptIds += 2; \ + nPts -= 2; \ + } \ + glEnd(); \ + ptIds += nPts; /* nPts could be 0 or -1 here */ \ + } \ +} + +void VISU_OpenGLElnoMapper::DrawPoints(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + vtkCellArray *ca, + vtkRenderer *ren) +{ + void *voidPoints = p->GetVoidPointer(0); + void *voidNormals = 0; + unsigned char *colors = 0; + if (ca->GetNumberOfCells() == 0) + { + return; + } + if (n) + { + voidNormals = n->GetVoidPointer(0); + } + if (c) + { + colors = c->GetPointer(0); + } + + vtkIdType *ptIds = ca->GetPointer(); + vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries(); + + + // draw all the elements, use fast path if available + switch (idx) + { + case VTK_PDM_POINT_TYPE_FLOAT: + vtkDrawPointsMacro(float, float, glVertex3fv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_DOUBLE: + vtkDrawPointsMacro(double, float, glVertex3dv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS: + vtkDrawPointsMacro(float, float, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals;); + + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS: + vtkDrawPointsMacro(float, float, + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;); + + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPointsMacro(float, float, + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS: + vtkDrawPointsMacro(float, float, + glNormal3fv(normals + 3**ptIds); + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPointsMacro(float, float, + glNormal3fv(normals + 3**ptIds); + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals;); + break; + default: + { + int j; + vtkIdType *pts = 0; + vtkIdType npts = 0; + unsigned short count = 0; + glBegin(GL_POINTS); + for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts); + count++) + { + for (j = 0; j < npts; j++) + { + if (c) + { + if (idx & 0x08) + { + glColor4ubv(c->GetPointer(cellNum << 2)); + } + else + { + glColor4ubv(c->GetPointer(pts[j]<< 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(pts[j])); + } + else + { + glTexCoord2dv(t->GetTuple(pts[j])); + } + } + if (n) + { + if (idx & 0x10) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(pts[j])); + } + } + glVertex3dv(p->GetPoint(pts[j])); + } + + // check for abort condition + if (count == 10000) + { + count = 0; + // report progress + this->UpdateProgress((double)cellNum/this->TotalCells); + if (ren->GetRenderWindow()->CheckAbortStatus()) + { + noAbort = 0; + } + } + ++cellNum; + } + glEnd(); + } + } +} + + +void VISU_OpenGLElnoMapper::DrawLines(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + vtkCellArray *ca, + vtkRenderer *ren) +{ + void *voidPoints = p->GetVoidPointer(0); + void *voidNormals = 0; + void *voidTCoords = 0; + unsigned char *colors = 0; + if (ca->GetNumberOfCells() == 0) + { + return; + } + if (n) + { + voidNormals = n->GetVoidPointer(0); + } + if (t) + { + voidTCoords = t->GetVoidPointer(0); + } + if (c) + { + colors = c->GetPointer(0); + } + vtkIdType *ptIds = ca->GetPointer(); + vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries(); + + // draw all the elements, use fast path if available + switch (idx) + { + case VTK_PDM_POINT_TYPE_FLOAT: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glVertex3fv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_DOUBLE: + vtkDrawPrimsMacro(double, float, GL_LINE_STRIP, + glVertex3dv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals;); + + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glNormal3fv(normals + 3**ptIds); + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals; + ); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glNormal3fv(normals + 3**ptIds); + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + float *normals = (float *)voidNormals; + ); + break; + case VTK_PDM_POINT_TYPE_FLOAT | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);, + float *tcoords = (float *)voidTCoords; + ); + break; + case VTK_PDM_POINT_TYPE_FLOAT | + VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawPrimsMacro(float, float, GL_LINE_STRIP, + glNormal3fv(normals + 3**ptIds); + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);, + float *tcoords = (float *)voidTCoords; + float *normals = (float *)voidNormals; + ); + break; + default: + { + int j; + vtkIdType *pts = 0; + vtkIdType npts = 0; + unsigned short count = 0; + for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts); + count++) + { + glBegin(GL_LINE_STRIP); + for (j = 0; j < npts; j++) + { + if (c) + { + if (idx & 0x08) + { + glColor4ubv(c->GetPointer(cellNum << 2)); + } + else + { + glColor4ubv(c->GetPointer(pts[j] << 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(pts[j])); + } + else + { + glTexCoord2dv(t->GetTuple(pts[j])); + } + } + if (n) + { + if (idx & 0x10) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(pts[j])); + } + } + glVertex3dv(p->GetPoint(pts[j])); + } + glEnd(); + + // check for abort condition + if (count == 10000) + { + count = 0; + // report progress + this->UpdateProgress((double)cellNum/this->TotalCells); + if (ren->GetRenderWindow()->CheckAbortStatus()) + { + noAbort = 0; + } + } + ++cellNum; + } + } + } +} + + + + + + + + + +#define PolyNormal \ +{ double polyNorm[3]; vtkPolygon::ComputeNormal(p,nPts,ptIds,polyNorm); glNormal3dv(polyNorm); } + +void VISU_OpenGLElnoMapper::DrawPolygons(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + GLenum rep, + vtkCellArray *ca, + vtkRenderer *ren) +{ + void *voidPoints = p->GetVoidPointer(0); + void *voidNormals = 0; + void *voidTCoords = 0; + unsigned char *colors = 0; + if (ca->GetNumberOfCells() == 0) + { + return; + } + if (n) + { + voidNormals = n->GetVoidPointer(0); + } + if (c) + { + colors = c->GetPointer(0); + // if these are cell colors then advance to the first cell + if (idx & VTK_PDM_CELL_COLORS) + { + colors = colors + cellNum*4; + } + } + if (t) + { + voidTCoords = t->GetVoidPointer(0); + } vtkIdType *ptIds = ca->GetPointer(); + vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries(); + + // draw all the elements, use fast path if available + switch (idx) + { + case VTK_PDM_POINT_TYPE_FLOAT: + vtkDrawPolysMacro(float, float, float, rep, + glVertex3fv(points + 3**ptIds);, + PolyNormal,;); + break; + case VTK_PDM_POINT_TYPE_DOUBLE: + vtkDrawPolysMacro(double, float, float, rep, + glVertex3dv(points + 3**ptIds);, + PolyNormal,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + PolyNormal,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + PolyNormal,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_CELL_NORMALS | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3;, + float *tcoords = (float *)voidTCoords; + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);, + PolyNormal;, + float *tcoords = (float *)voidTCoords;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord2fv(tcoords + 2**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT| + VTK_PDM_CELL_NORMALS: + vtkDrawPolysMacro(float, float, float, rep, + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3;, + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3;, + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3;, + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_CELL_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);, + glColor4ubv(colors); colors += 4;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS | + VTK_PDM_CELL_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);, + glColor3ubv(colors); colors += 4;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_CELL_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3; + glColor4ubv(colors); colors += 4;, + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS | + VTK_PDM_CELL_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glVertex3fv(points + 3**ptIds);, + glNormal3fv(normals); normals += 3; + glColor3ubv(colors); colors += 4;, + float *normals = (float *)voidNormals; + normals += cellNum*3;); + break; + default: + { + int j; + vtkIdType *pts = 0; + vtkIdType npts = 0; + vtkIdType np = 0; + unsigned short count = 0; + for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts); + count++) + { + glBegin(rep); + if (!n) + { + double polyNorm[3]; + vtkPolygon::ComputeNormal(p,npts,pts,polyNorm); + glNormal3dv(polyNorm); + } + for (j = 0; j < npts; j++) + { + if (c) + { + if (idx & VTK_PDM_CELL_COLORS) + { + glColor4ubv(c->GetPointer(np << 2)); + np++; + } + else + { + glColor4ubv(c->GetPointer(pts[j] << 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(pts[j])); + } + else + { + glTexCoord2dv(t->GetTuple(pts[j])); + } + } + if (n) + { + if (idx & VTK_PDM_CELL_NORMALS) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(pts[j])); + } + } + glVertex3dv(p->GetPoint(pts[j])); + } + glEnd(); + + // check for abort condition + if (count == 10000) + { + count = 0; + // report progress + this->UpdateProgress((double)cellNum/this->TotalCells); + if (ren->GetRenderWindow()->CheckAbortStatus()) + { + noAbort = 0; + } + } + ++cellNum; + } + } + } +} + +// fix refs here +#define TStripNormal \ +if ( vcount > 2) \ +{ \ + if (vcount % 2) \ + { \ + normIdx[0] = ptIds[-2]; normIdx[1] = ptIds[0]; normIdx[2] = ptIds[-1]; \ + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); \ + } \ + else \ + { \ + normIdx[0] = ptIds[-2]; normIdx[1] = ptIds[-1]; normIdx[2] = ptIds[0]; \ + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); \ + } \ + glNormal3dv(polyNorm); \ +} \ +vcount++; + +#define TStripNormalStart \ + vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm); \ + glNormal3dv(polyNorm); int vcount = 0; + +void VISU_OpenGLElnoMapper::DrawTStrips(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + GLenum rep, + vtkCellArray *ca, + vtkRenderer *ren) +{ + void *voidPoints = p->GetVoidPointer(0); + void *voidNormals = 0; + void *voidTCoords = 0; + unsigned char *colors = 0; + double polyNorm[3]; + vtkIdType normIdx[3]; + + if (ca->GetNumberOfCells() == 0) + { + return; + } + if (n) + { + voidNormals = n->GetVoidPointer(0); + } + if (c) + { + colors = c->GetPointer(0); + } + if (t) + { + voidTCoords = t->GetVoidPointer(0); + } + vtkIdType *ptIds = ca->GetPointer(); + vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries(); + + // draw all the elements, use fast path if available + switch (idx) + { + case VTK_PDM_POINT_TYPE_FLOAT: + vtkDrawPolysMacro(float, float, float, rep, + TStripNormal glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_DOUBLE: + vtkDrawPolysMacro(double, float, float, rep, + TStripNormal glVertex3dv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + TStripNormal + glColor4ubv(colors + (*ptIds << 2)); + glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + TStripNormal + glColor3ubv(colors + (*ptIds << 2)); + glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor4ubv(colors + (*ptIds << 2)); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor3ubv(colors + (*ptIds << 2)); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS | + VTK_PDM_TCOORD_1D | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS: + vtkDrawPolysMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord2fv(tcoords + 2**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + default: + { + int j; + vtkIdType nPts = 0; + unsigned short count = 0; + unsigned long coloroffset = cellNum; + for (ca->InitTraversal(); noAbort && ca->GetNextCell(nPts,ptIds); + count++) + { + glBegin(rep); + vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm); + glNormal3dv(polyNorm); + for (j = 0; j < nPts; j++) + { + if (c) + { + if ( (idx & VTK_PDM_USE_FIELD_DATA) && j>=2 ) + { + glColor4ubv(c->GetPointer(coloroffset << 2)); + coloroffset++; + } + else if (idx & VTK_PDM_CELL_COLORS) + { + glColor4ubv(c->GetPointer(cellNum << 2)); + } + else + { + glColor4ubv(c->GetPointer(ptIds[j] << 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(ptIds[j])); + } + else + { + glTexCoord2dv(t->GetTuple(ptIds[j])); + } + } + if (n) + { + if (idx & VTK_PDM_CELL_NORMALS) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(ptIds[j])); + } + } + else + { + if (j >= 2) + { + if (j % 2) + { + normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j]; + normIdx[2] = ptIds[j-1]; + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); + } + else + { + normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j-1]; + normIdx[2] = ptIds[j]; + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); + } + } + glNormal3dv(polyNorm); + } + glVertex3dv(p->GetPoint(ptIds[j])); + } + glEnd(); + + // check for abort condition + if (count == 10000) + { + count = 0; + // report progress + this->UpdateProgress((double)cellNum/this->TotalCells); + if (ren->GetRenderWindow()->CheckAbortStatus()) + { + noAbort = 0; + } + } + ++cellNum; + } + } + } +} + +void vtkOpenGLPolyDataMapperDrawTStripLines(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + GLenum rep, + vtkCellArray *ca, + vtkRenderer *ren) +{ + void *voidPoints = p->GetVoidPointer(0); + void *voidNormals = 0; + void *voidTCoords = 0; + unsigned char *colors = 0; + double polyNorm[3]; + vtkIdType normIdx[3]; + + if (n) + { + voidNormals = n->GetVoidPointer(0); + } + if (c) + { + colors = c->GetPointer(0); + } + if (t) + { + voidTCoords = t->GetVoidPointer(0); + } + vtkIdType *ptIds = ca->GetPointer(); + vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries(); + + // draw all the elements, use fast path if available + switch (idx) + { + case VTK_PDM_POINT_TYPE_FLOAT: + vtkDrawStripLinesMacro(float, float, float, rep, + TStripNormal; glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_DOUBLE: + vtkDrawStripLinesMacro(double, float, float, rep, + TStripNormal glVertex3dv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS: + vtkDrawStripLinesMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS: + vtkDrawStripLinesMacro(float, float, float, rep, + TStripNormal; + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawStripLinesMacro(float, float, float, rep, + TStripNormal; + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);, + TStripNormalStart,;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS: + vtkDrawStripLinesMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor4ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS: + vtkDrawStripLinesMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glColor3ubv(colors + 4**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS | + VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS: + vtkDrawStripLinesMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord1fv(tcoords + *ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | + VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS: + vtkDrawStripLinesMacro(float, float, float, rep, + glNormal3fv(normals + 3**ptIds); + glTexCoord2fv(tcoords + 2**ptIds); + glVertex3fv(points + 3**ptIds);,;, + float *normals = (float *)voidNormals; + float *tcoords = (float *)voidTCoords;); + break; + default: + { + int j; + vtkIdType nPts = 0; + int count = 0; + unsigned long coloroffset = cellNum; + for (ca->InitTraversal(); noAbort && ca->GetNextCell(nPts,ptIds); + count++) + { + glBegin(rep); + for (j = 0; j < nPts; j += 2) + { + if (c) + { + if ( (idx & VTK_PDM_USE_FIELD_DATA) && j >= 2) + { + glColor4ubv(c->GetPointer((coloroffset+j) << 2)); + } + else if (idx & VTK_PDM_CELL_COLORS) + { + glColor4ubv(c->GetPointer(cellNum << 2)); + } + else + { + glColor4ubv(c->GetPointer(ptIds[j] << 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(ptIds[j])); + } + else + { + glTexCoord2dv(t->GetTuple(ptIds[j])); + } + } + if (n) + { + if (idx & VTK_PDM_CELL_NORMALS) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(ptIds[j])); + } + } + else + { + if ( j == 0 ) + { + vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm); + } + else + { + normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j-1]; + normIdx[2] = ptIds[j]; + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); + } + glNormal3dv(polyNorm); + } + glVertex3dv(p->GetPoint(ptIds[j])); + } + glEnd(); + + glBegin(rep); + for (j = 1; j < nPts; j += 2) + { + if (c) + { + if ( (idx & VTK_PDM_USE_FIELD_DATA) && j >= 2) + { + glColor4ubv(c->GetPointer((coloroffset+j) << 2)); + } + else if (idx & VTK_PDM_CELL_COLORS) + { + glColor4ubv(c->GetPointer(cellNum << 2)); + } + else + { + glColor4ubv(c->GetPointer(ptIds[j] << 2)); + } + } + if (t) + { + if (idx & VTK_PDM_TCOORD_1D) + { + glTexCoord1dv(t->GetTuple(ptIds[j])); + } + else + { + glTexCoord2dv(t->GetTuple(ptIds[j])); + } + } + if (n) + { + if (idx & VTK_PDM_CELL_NORMALS) + { + glNormal3dv(n->GetTuple(cellNum)); + } + else + { + glNormal3dv(n->GetTuple(ptIds[j])); + } + } + else + { + if (j == 1) + { + vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm); + } + else + { + normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j]; + normIdx[2] = ptIds[j-1]; + vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); + } + glNormal3dv(polyNorm); + } + glVertex3dv(p->GetPoint(ptIds[j])); + } + glEnd(); + + // check for abort condition + if (count == 100) + { + count = 0; + if (ren->GetRenderWindow()->CheckAbortStatus()) + { + noAbort = 0; + } + } + ++cellNum; + coloroffset += (nPts >= 2)? (nPts - 2) : 0; + } + } + } +} + +// Draw method for OpenGL. +int VISU_OpenGLElnoMapper::Draw(vtkRenderer *aren, vtkActor *act) +{ + vtkOpenGLRenderer *ren = (vtkOpenGLRenderer *)aren; + int rep, interpolation; + float tran; + vtkProperty *prop; + vtkPoints *p; + vtkUnsignedCharArray *c=NULL; + vtkDataArray *n; + vtkDataArray *t; + int tDim; + int noAbort = 1; + vtkPolyData *input = this->GetInput(); + int cellScalars = 0; + vtkIdType cellNum = 0; + int cellNormals; + int resolve=0, zResolve=0; + double zRes = 0.0; + + // get the property + prop = act->GetProperty(); + + // get the transparency + tran = prop->GetOpacity(); + + // if the primitives are invisable then get out of here + if (tran <= 0.0) + { + return noAbort; + } + + // get the representation (e.g., surface / wireframe / points) + rep = prop->GetRepresentation(); + + // get the shading interpolation + interpolation = prop->GetInterpolation(); + + // and draw the display list + p = input->GetPoints(); + + // are they cell or point scalars + if ( this->Colors ) + { + c = this->Colors; + if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA || + this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA || + this->ScalarMode == VTK_SCALAR_MODE_USE_FIELD_DATA || + !input->GetPointData()->GetScalars() ) + && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) + { + cellScalars = 1; + } + } + + n = input->GetPointData()->GetNormals(); + if (interpolation == VTK_FLAT) + { + n = 0; + } + + cellNormals = 0; + if (n == 0 && input->GetCellData()->GetNormals()) + { + cellNormals = 1; + n = input->GetCellData()->GetNormals(); + } + + // if we are doing vertex colors then set lmcolor to adjust + // the current materials ambient and diffuse values using + // vertex color commands otherwise tell it not to. + glDisable( GL_COLOR_MATERIAL ); + if (c) + { + GLenum lmcolorMode; + if (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT) + { + if (prop->GetAmbient() > prop->GetDiffuse()) + { + lmcolorMode = GL_AMBIENT; + } + else + { + lmcolorMode = GL_DIFFUSE; + } + } + else if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT_AND_DIFFUSE) + { + lmcolorMode = GL_AMBIENT_AND_DIFFUSE; + } + else if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT) + { + lmcolorMode = GL_AMBIENT; + } + else // if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE) + { + lmcolorMode = GL_DIFFUSE; + } + glColorMaterial( GL_FRONT_AND_BACK, lmcolorMode); + glEnable( GL_COLOR_MATERIAL ); + } + + unsigned long idx = 0; + if (n && !cellNormals) + { + idx |= VTK_PDM_NORMALS; + } + if (c) + { + idx |= VTK_PDM_COLORS; + if (c->GetName()) + { // In the future, I will look at the number of components. + // All paths will have to handle 3 componet colors. + idx |= VTK_PDM_OPAQUE_COLORS; + } + } + if (cellScalars) + { + idx |= VTK_PDM_CELL_COLORS; + } + if (cellNormals) + { + idx |= VTK_PDM_CELL_NORMALS; + } + if (this->ScalarMode == VTK_SCALAR_MODE_USE_FIELD_DATA) + { + idx |= VTK_PDM_USE_FIELD_DATA; + } + + // store the types in the index + if (p->GetDataType() == VTK_FLOAT) + { + idx |= VTK_PDM_POINT_TYPE_FLOAT; + } + else if (p->GetDataType() == VTK_DOUBLE) + { + idx |= VTK_PDM_POINT_TYPE_DOUBLE; + } + if (n) + { + if (n->GetDataType() == VTK_FLOAT) + { + idx |= VTK_PDM_NORMAL_TYPE_FLOAT; + } + else if (n->GetDataType() == VTK_DOUBLE) + { + idx |= VTK_PDM_NORMAL_TYPE_DOUBLE; + } + } + + // Texture and color by texture + t = input->GetPointData()->GetTCoords(); + if ( t ) + { + tDim = t->GetNumberOfComponents(); + if (tDim > 2) + { + vtkDebugMacro(<< "Currently only 1d and 2d textures are supported.\n"); + t = NULL; + } + } + // Set the texture if we are going to use texture + // for coloring with a point attribute. + // fixme ... make the existance of the coordinate array the signal. + if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates && + ! (idx & VTK_PDM_CELL_COLORS)) + { + t = this->ColorCoordinates; + } + // Set the flags + if (t) + { + idx |= VTK_PDM_TCOORDS; + if (t->GetDataType() == VTK_FLOAT) + { + idx |= VTK_PDM_TCOORD_TYPE_FLOAT; + } + else if (t->GetDataType() == VTK_DOUBLE) + { + idx |= VTK_PDM_TCOORD_TYPE_DOUBLE; + } + if (t->GetNumberOfComponents() == 1) + { + idx |= VTK_PDM_TCOORD_1D; + } + // Not 1D assumes 2D texture coordinates. + } + + if ( this->GetResolveCoincidentTopology() ) + { + resolve = 1; + if ( this->GetResolveCoincidentTopology() == VTK_RESOLVE_SHIFT_ZBUFFER ) + { + zResolve = 1; + zRes = this->GetResolveCoincidentTopologyZShift(); + } + else + { +#ifdef GL_VERSION_1_1 + double f, u; + glEnable(GL_POLYGON_OFFSET_FILL); + this->GetResolveCoincidentTopologyPolygonOffsetParameters(f,u); + glPolygonOffset(f,u); +#endif + } + } + + // we need to know the total number of cells so that we can report progress + this->TotalCells = + input->GetVerts()->GetNumberOfCells() + + input->GetLines()->GetNumberOfCells() + + input->GetPolys()->GetNumberOfCells() + + input->GetStrips()->GetNumberOfCells(); + + // For verts or lines that have no normals, disable shading. + // This will fall back on the color set in the glColor4fv() + // call in vtkOpenGLProperty::Render() - the color returned + // by vtkProperty::GetColor() with alpha set to 1.0. + if (!n) + { + glDisable( GL_LIGHTING); + } + + this->DrawPoints(idx,p,n,c,t,cellNum,noAbort,input->GetVerts(), ren); + + // do lines + if ( zResolve ) + { + glDepthRange(zRes, 1.); + } + if (rep == VTK_POINTS) + { + this->DrawPoints(idx,p,n,c,t,cellNum, noAbort,input->GetLines(), ren); + } + else + { + this->DrawLines(idx,p,n,c,t,cellNum, noAbort, input->GetLines(), ren); + } + + // reset the lighting if we turned it off + if (!n) + { + glEnable( GL_LIGHTING); + } + + // disable shading if we are rendering points, but have no normals + if (!n && rep == VTK_POINTS) + { + glDisable( GL_LIGHTING); + } + + // do polys + if (rep == VTK_POINTS && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling() ) + { + this->DrawPoints(idx,p,n,c,t,cellNum, noAbort, input->GetPolys(), ren); + } + else if (rep == VTK_WIREFRAME && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling()) + { + this->DrawPolygons(idx,p,n,c,t,cellNum, noAbort, + GL_LINE_LOOP, input->GetPolys(), ren); + } + else + { + this->DrawPolygons(idx,p,n,c,t,cellNum, noAbort, + GL_POLYGON, input->GetPolys(), ren); + } + + + // do tstrips + if ( zResolve ) + { + glDepthRange(2*zRes, 1.); + } + if (rep == VTK_POINTS && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling() ) + { + this->DrawPoints(idx,p,n,c,t,cellNum, noAbort, input->GetStrips(), ren); + } + else if (rep == VTK_WIREFRAME && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling()) + { + vtkIdType oldCellNum = cellNum; + this->DrawTStrips(idx,p,n,c,t,cellNum, noAbort, + GL_LINE_STRIP, input->GetStrips(), ren); + vtkOpenGLPolyDataMapperDrawTStripLines(idx,p,n,c,t,oldCellNum, noAbort, + GL_LINE_STRIP, input->GetStrips(), + ren); + } + else + { + this->DrawTStrips(idx,p,n,c,t,cellNum, noAbort, + GL_TRIANGLE_STRIP, input->GetStrips(), ren); + } + + // enable lighting again if necessary + if (!n && rep == VTK_POINTS) + { + glEnable( GL_LIGHTING); + } + + if (resolve) + { + if ( zResolve ) + { + glDepthRange(0., 1.); + } + else + { +#ifdef GL_VERSION_1_1 + glDisable(GL_POLYGON_OFFSET_FILL); +#endif + } + } + + this->UpdateProgress(1.0); + return noAbort; +} + +void VISU_OpenGLElnoMapper::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} + + + +//----------------------------------------------------------------------------- +/*template +void CopyArray(TValueType* input,TValueType* output,vtkIdType theNbElem){ + + for(vtkIdType iTuple = 0; iTuple < theNbElem ; iTuple++){ + *output = *input; + input++; + output++; + } +} + +vtkDataArray* VISU_OpenGLElnoMapper::GetElnoScalars(int cellFlag){ + + vtkDataArray *scalars = vtkAbstractMapper:: + GetScalars(this->GetInput(), this->ScalarMode, this->ArrayAccessMode, + this->ArrayId, this->ArrayName, cellFlag); + + vtkIdType anInputDataType = scalars->GetDataType(); + + vtkDataArray *elnoScalars = vtkDataArray::CreateDataArray(anInputDataType); + vtkIdType aNbElnoTuples = VISU_ElnoExtractor::GetNbOfElnoTuples(this->GetInput()->GetCellData()); + elnoScalars->SetNumberOfComponents(1); + elnoScalars->SetNumberOfTuples(aNbElnoTuples); + + void *scalarsPtr = scalars->GetVoidPointer(0); + void *elnoScalarsPtr = elnoScalars->GetVoidPointer(0); + + switch(anInputDataType){ + vtkTemplateMacro3(CopyArray, + (VTK_TT *)(scalarsPtr), + (VTK_TT *)(elnoScalarsPtr), + aNbElnoTuples); + default: + break; + } + + return elnoScalars; + }*/ + + +vtkUnsignedCharArray *VISU_OpenGLElnoMapper::MapScalars(double alpha) +{ + int cellFlag = 0; + vtkDataArray *scalars = this->GetInput()->GetCellData()->GetArray("ELNO_PSEUDO_SCALARS"); + if(!scalars) + return NULL; + // This is for a legacy feature: selection of the array component to color by + // from the mapper. It is now in the lookuptable. When this feature + // is removed, we can remove this condition. + if (scalars == 0 || scalars->GetNumberOfComponents() <= this->ArrayComponent) + { + this->ArrayComponent = 0; + } + + if ( !this->ScalarVisibility || scalars==0 || this->GetInput()==0) + { // No scalar colors. + if ( this->ColorCoordinates ) + { + this->ColorCoordinates->UnRegister(this); + this->ColorCoordinates = 0; + } + if ( this->ColorTextureMap ) + { + this->ColorTextureMap->UnRegister(this); + this->ColorTextureMap = 0; + } + if ( this->Colors ) + { + this->Colors->UnRegister(this); + this->Colors = 0; + } + return 0; + } + + // Get the lookup table. + if ( scalars->GetLookupTable() ) + { + this->SetLookupTable(scalars->GetLookupTable()); + } + else + { + // make sure we have a lookup table + if ( this->LookupTable == 0 ) + { + this->CreateDefaultLookupTable(); + } + this->LookupTable->Build(); + } + if ( !this->UseLookupTableScalarRange ) + { + this->LookupTable->SetRange(this->ScalarRange); + } + + // Decide betweeen texture color or vertex color. + // Cell data always uses vertext color. + // Only point data can use both texture and vertext coloring. + if (this->InterpolateScalarsBeforeMapping && ! cellFlag) + { + // Only use texture color if we are mapping scalars. + // Directly coloring with RGB unsigned chars should not use texture. + if ( this->ColorMode != VTK_COLOR_MODE_DEFAULT || + (vtkUnsignedCharArray::SafeDownCast(scalars)) == 0 ) + { // Texture color option. + this->MapScalarsToTexture(scalars, alpha); + return 0; + } + } + + // Vertex colors are being used. + // Get rid of texure Color arrays. Only texture or vertex coloring + // can be active at one time. The existence of the array is the + // signal to use that technique. + if ( this->ColorCoordinates ) + { + this->ColorCoordinates->UnRegister(this); + this->ColorCoordinates = 0; + } + if ( this->ColorTextureMap ) + { + this->ColorTextureMap->UnRegister(this); + this->ColorTextureMap = 0; + } + + // Lets try to resuse the old colors. + if (this->Colors) + { + if (this->LookupTable && this->LookupTable->GetAlpha() == alpha) + { + if (this->GetMTime() < this->Colors->GetMTime() && + this->GetInput()->GetMTime() < this->Colors->GetMTime() && + this->LookupTable->GetMTime() < this->Colors->GetMTime()) + { + return this->Colors; + } + } + } + + // Get rid of old colors + if ( this->Colors ) + { + this->Colors->UnRegister(this); + this->Colors = 0; + } + + // map scalars + this->LookupTable->SetAlpha(alpha); + this->Colors = this->LookupTable-> + MapScalars(scalars, this->ColorMode, this->ArrayComponent); + // Consistent register and unregisters + this->Colors->Register(this); + this->Colors->Delete(); + + return this->Colors; +} diff --git a/src/PIPELINE/VISU_OpenGLElnoMapper.hxx b/src/PIPELINE/VISU_OpenGLElnoMapper.hxx new file mode 100755 index 00000000..be53c38d --- /dev/null +++ b/src/PIPELINE/VISU_OpenGLElnoMapper.hxx @@ -0,0 +1,106 @@ + +#ifndef VISU_OpenGLElnoMapper_HeaderFile +#define VISU_OpenGLElnoMapper_HeaderFile + +#include "vtkPolyDataMapper.h" + +#include "vtkOpenGL.h" // Needed for GLenum + +class vtkCellArray; +class vtkPoints; +class vtkProperty; +class vtkRenderWindow; +class vtkOpenGLRenderer; +class vtkOpenGLTexture; + +class VTK_RENDERING_EXPORT VISU_OpenGLElnoMapper : public vtkPolyDataMapper +{ +public: + static VISU_OpenGLElnoMapper *New(); + vtkTypeRevisionMacro(VISU_OpenGLElnoMapper, vtkPolyDataMapper); + virtual void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Implement superclass render method. + virtual void RenderPiece(vtkRenderer *ren, vtkActor *a); + + // Description: + // Release any graphics resources that are being consumed by this mapper. + // The parameter window could be used to determine which graphic + // resources to release. + void ReleaseGraphicsResources(vtkWindow *); + + // Description: + // Draw method for OpenGL. + virtual int Draw(vtkRenderer *ren, vtkActor *a); + + // Description: + // Map the scalars (if there are any scalars and ScalarVisibility is on) + // through the lookup table, returning an unsigned char RGBA array. This is + // typically done as part of the rendering process. The alpha parameter + // allows the blending of the scalars with an additional alpha (typically + // which comes from a vtkActor, etc.) + +protected: + VISU_OpenGLElnoMapper(); + ~VISU_OpenGLElnoMapper(); + + + void DrawPoints(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + vtkCellArray *ca, + vtkRenderer *ren); + + void DrawLines(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + vtkCellArray *ca, + vtkRenderer *ren); + + void DrawPolygons(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + GLenum rep, + vtkCellArray *ca, + vtkRenderer *ren); + + void DrawTStrips(int idx, + vtkPoints *p, + vtkDataArray *n, + vtkUnsignedCharArray *c, + vtkDataArray *t, + vtkIdType &cellNum, + int &noAbort, + GLenum rep, + vtkCellArray *ca, + vtkRenderer *ren); + + vtkIdType TotalCells; + int ListId; + vtkOpenGLTexture* InternalColorTexture; + + // vtkDataArray* GetElnoScalars(int cellFlag); + vtkUnsignedCharArray* MapScalars(double alpha); + + + /*private: + + vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&); // Not implemented. + void operator=(const vtkOpenGLPolyDataMapper&); // Not implemented. + */ +}; + +#endif