#include "VISU_VTKTypeList.hxx"
+class vtkDataSetAttributes;
+
/*!
\file VISU_ElnoMeshValue.hxx
\brief The file contains declarations for the acess to the specific ELNO MED data
//----------------------------------------------------------------------------
TGetElnoNodeData( vtkDataArray *theElnoDataArray,
- vtkIntArray *theElnoDataMapper )
+ vtkDataArray *theElnoDataMapper )
: myElnoDataArray( TVTKDataArray::SafeDownCast( theElnoDataArray ) )
- , myElnoDataMapper( theElnoDataMapper )
+ , myElnoDataMapper( vtkIntArray::SafeDownCast( theElnoDataMapper ) )
{}
operator () ( vtkIdType theCellId, vtkIdType theLocalPntId )
{
myElnoDataMapper->GetTupleValue( theCellId, myElemInfo );
- return myElnoDataArray->GetPointer( myElemInfo[ 0 ] );
+
+ vtkIdType aPos = myElemInfo[ 0 ] + theLocalPntId * myElemInfo[ 1 ];
+
+ return myElnoDataArray->GetPointer( aPos );
}
getNbComp()
{
myElnoDataMapper->GetTupleValue( 0, myElemInfo );
+
return myElemInfo[ 1 ];
}
};
+ //----------------------------------------------------------------------------------------------
+ template< int elno_type >
+ struct TSetElnoNodeData
+ {
+ typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray;
+ typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType;
+
+ //----------------------------------------------------------------------------------------------
+ TSetElnoNodeData( vtkIdType theEffectNbComp,
+ vtkIdType theRealNbComp,
+ vtkIdType theNbTuples,
+ const char* theDataArrayName,
+ const char* theMapperArrayName )
+ : myElnoDataArray( TVTKDataArray::New() )
+ , myElnoDataMapper( vtkIntArray::New() )
+ {
+ myElnoDataArray->SetNumberOfComponents( theEffectNbComp );
+ myElnoDataArray->SetNumberOfTuples( theNbTuples );
+ myElnoDataArray->SetName( theDataArrayName );
+
+ myElnoDataMapper->SetNumberOfComponents( 3 );
+ myElnoDataMapper->Allocate( theNbTuples * 3 );
+ myElnoDataMapper->SetName( theMapperArrayName );
+
+ myElemInfo[ 0 ] = 0;
+ myElemInfo[ 1 ] = theRealNbComp;
+ myElemInfo[ 2 ] = 0;
+ }
+
+
+ //----------------------------------------------------------------------------------------------
+ ~TSetElnoNodeData()
+ {
+ myElnoDataArray->Delete();
+ myElnoDataMapper->Delete();
+ }
+
+
+ //----------------------------------------------------------------------------------------------
+ int
+ AddNextPointData( TDataType* theDataPtr )
+ {
+ vtkIdType aPos = myElemInfo[ 0 ] + myElemInfo[ 2 ] * myElemInfo[ 1 ];
+
+ TDataType* aDataPtr = myElnoDataArray->GetPointer( aPos );
+
+ for ( vtkIdType aCompId = 0; aCompId < myElemInfo[ 1 ]; aCompId++ )
+ *aDataPtr++ = *theDataPtr++;
+
+ return myElemInfo[ 2 ]++;
+ }
+
+
+ //----------------------------------------------------------------------------------------------
+ void
+ InsertNextCellData()
+ {
+ myElnoDataMapper->InsertNextTupleValue( myElemInfo );
+ myElemInfo[ 0 ] = myElemInfo[ 2 ];
+ myElemInfo[ 2 ] = 0;
+ }
+
+
+ //----------------------------------------------------------------------------------------------
+ void
+ AddData( vtkDataSetAttributes* theDataSetAttributes )
+ {
+ theDataSetAttributes->AddArray( myElnoDataArray );
+ theDataSetAttributes->AddArray( myElnoDataMapper );
+ }
+
+ protected:
+ TVTKDataArray *myElnoDataArray;
+ vtkIntArray *myElnoDataMapper;
+ int myElemInfo[ 3 ];
+ };
+
+
//---------------------------------------------------------------
}
#include "VISU_ElnoGeometryFilter.hxx"
#include "VISU_ConvertorUtils.hxx"
+#include "VISU_ElnoMeshValue.hxx"
#include <vtkCellArray.h>
#include <vtkCellData.h>
myMinMax[0] = -VTK_DOUBLE_MAX;
myMinMax[1] = VTK_DOUBLE_MAX;
}
+
//----------------------------------------------------------------------------------------------
VISU_ElnoGeometryFilter::~VISU_ElnoGeometryFilter()
{
}
}
+
//----------------------------------------------------------------------------------------------
-int VISU_ElnoGeometryFilter::RequestData(vtkInformation *request,
- vtkInformationVector **inputVector,
- vtkInformationVector *outputVector)
+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()));
+ vtkDataSet *input = vtkDataSet::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT() ) );
+ vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT() ) );
vtkIdType numCells=input->GetNumberOfCells();
+ if ( numCells == 0 )
+ return 0;
- if(!InitInternalArray(input))
- return 1;
+ if ( !InitInternalArray( input ) )
+ return 0;
- if (numCells == 0)
- {
- return 1;
+ switch ( input->GetDataObjectType() ) {
+ case VTK_UNSTRUCTURED_GRID :
+ return this->UnstructuredGridExecute( vtkUnstructuredGrid::SafeDownCast( input ) , output, outInfo );
+ case VTK_POLY_DATA :
+ return this->PolyDataExecute( vtkPolyData::SafeDownCast( input ), output, outInfo );
+ default :
+ return Superclass::RequestData( request, inputVector, outputVector );
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------------------------------
+namespace
+{
+ template < int elno_type >
+ int PolyDataExecute( vtkPolyData *input,
+ vtkPolyData *output,
+ int theScalarMode,
+ vtkFloatingPointType* theMinMax )
+ {
+ vtkDataArray* anElnoDataArray = input->GetCellData()->GetArray( "ELNO_FIELD" );
+ vtkDataArray* anElnoDataMapper = input->GetCellData()->GetArray( "ELNO_COMPONENT_MAPPER" );
+
+ theMinMax[ 0 ] = VTK_DOUBLE_MAX;
+ theMinMax[ 1 ] = -VTK_DOUBLE_MAX;
+
+ vtkIdType aNbConnectivity = 0;
+
+ if ( vtkCellArray* aCellArray = input->GetVerts() )
+ aNbConnectivity += aCellArray->GetSize();
+
+ if ( vtkCellArray* aCellArray = input->GetLines() )
+ aNbConnectivity += aCellArray->GetSize();
+
+ if ( vtkCellArray* aCellArray = input->GetPolys() )
+ aNbConnectivity += aCellArray->GetSize();
+
+ if ( vtkCellArray* aCellArray = input->GetStrips() )
+ aNbConnectivity += aCellArray->GetSize();
+
+ vtkIdType aNbCells = input->GetNumberOfCells();
+ vtkIdType anEffectNbComp = aNbConnectivity / aNbCells;
+
+ VISU::TGetElnoNodeData< elno_type > aGetElnoNodeData( anElnoDataArray, anElnoDataMapper );
+ typedef typename VISU::TL::TEnum2VTKBasicType< elno_type >::TResult TElnoDataType;
+ vtkIdType aNbDim = std::min( 3, aGetElnoNodeData.getNbComp() );
+
+ VISU::TSetElnoNodeData< elno_type > aSetElnoNodeData( anEffectNbComp,
+ 1,
+ aNbCells,
+ "ELNO_PSEUDO_SCALARS",
+ "ELNO_PSEUDO_SCALARS_MAPPER" );
+
+ input->BuildCells();
+ vtkIdType aNbPts = 0, *aPts = 0;
+ for ( vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++ ) {
+ input->GetCellPoints( aCellId, aNbPts, aPts );
+
+ for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+ vtkIdType aCurrentPntId = aPts[ aPntId ];
+ TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aCurrentPntId );
+
+ TElnoDataType anElnoValue = 0;
+ if ( theScalarMode > 0 ) {
+ anElnoValue = anElnoData[ theScalarMode - 1 ];
+ } else {
+ for ( vtkIdType aDimId = 0; aDimId < aNbDim; aDimId++ )
+ anElnoValue += anElnoData[ aDimId ] * anElnoData[ aDimId ];
+
+ anElnoValue = TElnoDataType( sqrt( anElnoValue ) );
+ }
+
+ aSetElnoNodeData.AddNextPointData( &anElnoValue );
+
+ theMinMax[ 0 ] = std::min( theMinMax[ 0 ], vtkFloatingPointType( anElnoValue ) );
+ theMinMax[ 1 ] = std::max( theMinMax[ 1 ], vtkFloatingPointType( anElnoValue ) );
+ }
+
+ aSetElnoNodeData.InsertNextCellData();
}
+
+ aSetElnoNodeData.AddData( output->GetCellData() );
- if (input->GetDataObjectType() == VTK_UNSTRUCTURED_GRID){
- this->UnstructuredGridExecute(input, output, outInfo);
return 1;
- }else
- return Superclass::RequestData(request,inputVector,outputVector);
-
- return 1;
+ }
+
+
+ //----------------------------------------------------------------------------------------------
}
+
+
+//----------------------------------------------------------------------------------------------
+int VISU_ElnoGeometryFilter::PolyDataExecute( vtkPolyData *input,
+ vtkPolyData *output,
+ vtkInformation *outInfo )
+{
+ output->CopyStructure( input );
+ output->GetPointData()->PassData( input->GetPointData() );
+ output->GetCellData()->PassData( input->GetCellData() );
+
+ vtkDataArray* anElnoDataArray = input->GetCellData()->GetArray( "ELNO_FIELD" );
+ switch( anElnoDataArray->GetDataType() ){
+ case VTK_DOUBLE :
+ return ::PolyDataExecute< VTK_DOUBLE >( input, output, myScalarMode, myMinMax );
+ case VTK_FLOAT :
+ return ::PolyDataExecute< VTK_FLOAT >( input, output, myScalarMode, myMinMax );
+ case VTK_INT :
+ return ::PolyDataExecute< VTK_INT >( input, output, myScalarMode, myMinMax );
+ case VTK_LONG :
+ return ::PolyDataExecute< VTK_LONG >( input, output, myScalarMode, myMinMax );
+ default :
+ break;
+ }
+
+ return 0;
+}
+
+
//----------------------------------------------------------------------------------------------
template<typename TValueType>
void BuildMinMax(TValueType* inputPtr, double *outres, const vtkIdType& theDataSize){
inputPtr++;
}
}
+
+
//----------------------------------------------------------------------------------------------
-void VISU_ElnoGeometryFilter::UnstructuredGridExecute(vtkDataSet *dataSetInput,
- vtkPolyData *output,
- vtkInformation *outInfo)
+int VISU_ElnoGeometryFilter::UnstructuredGridExecute( vtkUnstructuredGrid *input,
+ vtkPolyData *output,
+ vtkInformation *outInfo )
{
- vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)dataSetInput;
+ // Check input
vtkCellArray *Connectivity = input->GetCells();
- if (Connectivity == NULL)
- {
- return;
- }
+ if ( Connectivity == NULL ) {
+ vtkDebugMacro(<<"Nothing to extract");
+ return 0;
+ }
vtkIdType cellId;
int i;
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();
{
delete [] cellVis;
}
+
+ return 1;
}
//----------------------------------------------------------------------------------------------
}
//----------------------------------------------------------------------------------------------
-double* VISU_ElnoGeometryFilter::GetRange(){
- this->Update(); // To perform automatic update if neccesary
- return myMinMax;
+void VISU_ElnoGeometryFilter::GetRange( vtkFloatingPointType *theRange )
+{
+ theRange[ 0 ] = +VTK_DOUBLE_MAX;
+ theRange[ 1 ] = -VTK_DOUBLE_MAX;
+
+ this->Update(); // To perform automatic update if no
+
+ theRange[ 0 ] = myMinMax[ 0 ];
+ theRange[ 1 ] = myMinMax[ 1 ];
}
//----------------------------------------------------------------------------------------------