Пример #1
0
// =============================================================================
void
VIO::Image::Writer::Abstract::
setImageData ( const Epetra_MultiVector              & x,
               const Teuchos::Tuple<unsigned int,2>  & Nx,
               const Point                           & h,
               const Teuchos::Array<int>             & p,
               const Teuchos::Array<std::string>     & scalarsNames
             )
{
    int numVecs   = x.NumVectors();
    int numPoints = ( Nx[0]+1 ) * ( Nx[1]+1 );

    // get scalarsNames, and insert default names if empty
    Teuchos::Array<std::string> scNames ( scalarsNames );
    if ( scNames.empty() )
    {
        scNames.resize ( numVecs );
        for ( int vec=0; vec<numVecs; vec++ )
            scNames[vec] = "x" + EpetraExt::toString ( vec );
    }

    // cast into vtkImageData
    vtkSmartPointer<vtkImageData> imageData =
        dynamic_cast<vtkImageData*> ( vtkDataSet_.GetPointer() );
    TEUCHOS_ASSERT_INEQUALITY( 0, !=, imageData );

    // set other image data
    imageData->SetDimensions ( Nx[0]+1, Nx[1]+1, 1 );
    imageData->SetOrigin ( 0.0, 0.0, 0.0 );
    imageData->SetSpacing ( h[0], h[1], 0.0 );

    // fill the scalar field
    vtkSmartPointer<vtkDoubleArray> scalars =
        vtkSmartPointer<vtkDoubleArray>::New();

    bool isScrambled = !p.empty();

    if ( isScrambled )
    {
        TEUCHOS_ASSERT_EQUALITY ( numPoints, p.length() );
        addFieldData ( p, "p" );
    }

    // fill the scalars vector and add it to imageData_
    if ( isScrambled )
    {
        double dummy = 0.0;
        for ( int vec=0; vec<numVecs; vec++ )
        {
            scalars->SetName ( scNames[vec].c_str() );
            for ( int k=0; k<numPoints; k++ )
                scalars->InsertNextValue ( p[k]>=0 ? x[vec][p[k]] : dummy );
            imageData->GetPointData()->AddArray ( scalars );
        }
    }
    else
        for ( int vec=0; vec<numVecs; vec++ )
        {
            scalars->SetName ( scNames[vec].c_str() );
            for ( int k=0; k<numPoints; k++ )
                scalars->InsertNextValue ( x[vec][k] );
            imageData->GetPointData()->AddArray ( scalars );
        }

    return;
}
Пример #2
0
// =============================================================================
void
VIO::Image::Writer::Abstract::
setImageData ( const ComplexMultiVector              & x,
               const Teuchos::Tuple<unsigned int,2>  & Nx,
               const Point                           & h,
               const Teuchos::Array<int>             & p,
               const Teuchos::Array<std::string>     & scalarsNames
             )
{
    int numVecs   = x.getNumVectors();
    int numPoints = ( Nx[0]+1 ) * ( Nx[1]+1 );

    // get scalarsNames, and insert default names if empty
    Teuchos::Array<std::string> scNames ( scalarsNames );
    if ( scNames.empty() )
    {
        scNames.resize ( numVecs );
        for ( int vec=0; vec<numVecs; vec++ )
            scNames[vec] = "z" + EpetraExt::toString ( vec );
    }
    
    // cast into vtkImageData
    vtkSmartPointer<vtkImageData> imageData =
        dynamic_cast<vtkImageData*> ( vtkDataSet_.GetPointer() );
    TEUCHOS_ASSERT_INEQUALITY( 0, !=, imageData );

    // set other image data
    imageData->SetDimensions ( Nx[0]+1, Nx[1]+1, 1 );
    imageData->SetOrigin ( 0.0, 0.0, 0.0 );
    imageData->SetSpacing ( h[0], h[1], 0.0 );

    // fill the scalar field
    vtkSmartPointer<vtkDoubleArray> scalars =
        vtkSmartPointer<vtkDoubleArray>::New();

    double dummy = 0.0;
    bool isScrambled = !p.empty();
    if ( isScrambled )
    {
        TEUCHOS_ASSERT_EQUALITY ( numPoints, p.length() );
        addFieldData ( p, "p" );
    }

    // real and imaginary part
    scalars->SetNumberOfComponents ( 2 );

    // fill the scalars vector and add it to imageData_
    Teuchos::ArrayRCP<const std::complex<double> > xView;
    for ( int vec=0; vec<numVecs; vec++ )
    {
        xView = x.getVector ( vec )->get1dView();
        scalars->SetName ( scNames[vec].c_str() );
        for ( int k=0; k<numPoints; k++ )
        {
            if ( isScrambled )
            {
                // TODO replace by InsertNextTuple
                scalars->InsertNextValue ( p[k]>=0 ? std::real ( xView[p[k]] ) : dummy );
                scalars->InsertNextValue ( p[k]>=0 ? std::imag ( xView[p[k]] ) : dummy );
            }
            else
            {
                scalars->InsertNextValue ( std::real ( xView[k] ) );
                scalars->InsertNextValue ( std::imag ( xView[k] ) );
            }
        }
        imageData->GetPointData()->AddArray ( scalars );
    }

    return;
}