surface.H 11.3 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7 8
-------------------------------------------------------------------------------
    Copyright (C) 2015-2019 OpenCFD Ltd.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
27
    Foam::functionObjects::runTimePostPro::surface
28 29

Description
30 31 32 33 34 35 36 37 38 39 40
    Visualisation of surface data with additional routines for handling
    parallel distributed data.

    Dictionary controls
    \table
        Property    | Description                           | Required | Default
        representation| none/glyph/wireframe/surface/surfaceWithEdges | yes |
        surfaceColour | Override surface colour             | no  |
        edgeColour    | Override edge colour                | no  |
        featureEdges  | Display surface feature edges       | no  | false
        maxGlyphLength | Limit for glyph representation     | yes | 0
41 42
        backFaceCulling | Cull back face                    | no  | false
        frontFaceCulling | Cull front face                  | no  | true
43
    \endtable
44 45 46

SourceFiles
    surface.C
47 48
    surfaceGather.C
    surfaceTemplates.C
49 50 51

\*---------------------------------------------------------------------------*/

52 53
#ifndef functionObjects_runTimePostPro_surface_H
#define functionObjects_runTimePostPro_surface_H
54 55

#include "geometryBase.H"
56
#include "DimensionedField.H"
57
#include "Enum.H"
58
#include "runTimeSelectionTables.H"
59

60
#include "vtkSmartPointer.h"
61
#include "vtkMultiPieceDataSet.h"
62 63 64

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

65
// Forward Declarations
66 67
class vtkActor;
class vtkRenderer;
68 69 70 71
class vtkCellData;
class vtkCompositeDataGeometryFilter;
class vtkFeatureEdges;
class vtkPointData;
72 73
class vtkPolyData;

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
namespace Foam
{
// Forward Declarations
class polySurface;
class polySurfaceGeoMesh;
class polySurfacePointGeoMesh;
}


// These need to shift elsewhere

namespace Foam
{
namespace vtk
{
namespace Tools
{

//- Functional call with null-pointer check
vtkCellData* GetCellData(vtkDataSet* dataset);

//- Functional call with null-pointer check
vtkPointData* GetPointData(vtkDataSet* dataset);


//- Default field access is vtkCellData
template<class Type>
struct FieldAccess
{
    vtkCellData* operator()(vtkDataSet* dataset) const
    {
        return Tools::GetCellData(dataset);
    }
};


// Specializations on OpenFOAM type

//- PointAccess for point fields (on polySurfacePointGeoMesh)
template<>
struct FieldAccess<::Foam::polySurfacePointGeoMesh>
{
    vtkPointData* operator()(vtkDataSet* dataset) const
    {
        return Tools::GetPointData(dataset);
    }
};

} // End namespace Tools
} // End namespace vtk
} // End namespace Foam


// More


130 131
namespace Foam
{
132 133 134 135
namespace functionObjects
{
namespace runTimePostPro
{
136 137 138 139 140 141 142 143 144 145 146 147 148

/*---------------------------------------------------------------------------*\
                          Class surface Declaration
\*---------------------------------------------------------------------------*/

class surface
:
    public geometryBase
{
public:

    // Public enumerations

149
        //- Surface representation types
150 151
        enum representationType
        {
152 153 154 155 156
            rtNone,             //!< "none"
            rtGlyph,            //!< "glyph"
            rtWireframe,        //!< "wireframe"
            rtSurface,          //!< "surface"
            rtSurfaceWithEdges  //!< "surfaceWithEdges"
157 158
        };

159
        //- Names for surface representation types
160
        static const Enum<representationType> representationTypeNames;
161 162 163 164


protected:

165
    // Protected Data
166 167 168 169 170 171 172

        //- Representation type
        representationType representation_;

        //- Activate feature edges
        bool featureEdges_;

173 174 175 176 177 178
        //- Back face culling option; default = off
        bool backFaceCulling_;

        //- Front face culling option; default = on
        bool frontFaceCulling_;

179
        //- Surface colour
180
        autoPtr<Function1<vector>> surfaceColour_;
181 182

        //- Edge colour
183
        autoPtr<Function1<vector>> edgeColour_;
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

        //- Surface actor
        vtkSmartPointer<vtkActor> surfaceActor_;

        //- Edge actor
        vtkSmartPointer<vtkActor> edgeActor_;

        //- Max glyph length for representation type rtGlyph
        scalar maxGlyphLength_;


    // Protected Member Functions

        //- Set the representation
        void setRepresentation(vtkActor* actor) const;

200 201 202 203 204 205 206
        //- Add feature edges to scene
        void addFeatureEdges
        (
            vtkRenderer* renderer,
            vtkFeatureEdges* featureEdges
        ) const;

207 208 209 210 211 212 213
        //- Add feature edges to scene
        void addFeatureEdges
        (
            vtkRenderer* renderer,
            vtkPolyData* data
        ) const;

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
        //- Add feature edges to scene
        void addFeatureEdges
        (
            vtkRenderer* renderer,
            vtkCompositeDataGeometryFilter* input
        ) const;


        //- Gather and convert polySurface to multi-piece dataset with
        //- vtkPolyData for the leaves.
        //  If VTK is also running in parallel, each surface is left
        //  as a processor-local piece. Otherwise all processor-local
        //  surfaces are gathered onto the master in their correponding
        //  slots.
        vtkSmartPointer<vtkMultiPieceDataSet>
        gatherSurfacePieces(const polySurface* surf) const;

        //- Gather and convert polySurface to multi-piece dataset with
        //- vtkPolyData for the leaves.
        //  If VTK is also running in parallel, each surface is left
        //  as a processor-local piece. Otherwise all processor-local
        //  surfaces are gathered onto the master in their correponding
        //  slots.
        vtkSmartPointer<vtkMultiPieceDataSet>
        gatherFaceCentres(const polySurface* surf) const;


    // Adding Fields - single-piece

        //- Add field of Type to piece as VTK field data in GeoMeshType slot.
        //  GeoMeshType distinguishes between vtkCellData and vtkPointData
        template<class Type, class GeoMeshType>
        bool addField
        (
            vtkDataSet* piece,       //!< The VTK piece (null protected)
            const Field<Type>& fld,  //!< The field values to add
            const word& fieldName    //!< The field name to use
        ) const;

        //- Attempt cast of regIOobject to DimensionedField\<Type\> and
        //- add to piece as VTK field data in GeoMeshType slot.
        //  GeoMeshType distinguishes between vtkCellData and vtkPointData
        template<class Type, class GeoMeshType>
        bool addDimField
        (
            vtkDataSet* piece,       //!< The VTK piece (null protected)
            const regIOobject* ioptr, //!< The field values to add
            const word& fieldName    //!< The field name to use
        ) const;

        //- Attempt cast of regIOobject to standard DimensionedField types
        //- and add to piece when possible
        template<class GeoMeshType>
        bool addDimField
        (
            vtkDataSet* piece,       //!< The VTK piece (null protected)
            const regIOobject* ioptr, //!< The field values to add
            const word& fieldName    //!< The field name to use
        ) const;


    // Adding Fields - multi-piece

        //- Add DimensionedField of Type to multi-piece as VTK field data in
        //- GeoMeshType slot (CELL | POINT).
        template<class Type, class GeoMeshType>
        bool addDimField
        (
            vtkMultiPieceDataSet* multiPiece,
            const DimensionedField<Type, GeoMeshType>* fldptr,
            const word& fieldName
        ) const;

        //- Attempt cast of regIOobject to DimensionedField\<Type\> and
        //- add in multi-piece as VTK field data in
        //- GeoMeshType slot (CELL | POINT).
        template<class Type, class GeoMeshType>
        bool addDimField
        (
            vtkMultiPieceDataSet* multiPiece, //!< The VTK pieces
            const regIOobject* ioptr, //!< The field values to add
            const word& fieldName    //!< The field name to use
        ) const;

        //- Attempt cast of regIOobject to standard DimensionedField types
        //- and add when possible in GeoMeshType slot (CELL | POINT).
        template<class GeoMeshType>
        bool addDimField
        (
            vtkMultiPieceDataSet* multiPiece, //!< The VTK pieces
            const regIOobject* ioptr, //!< The field values to add
            const word& fieldName    //!< The field name to use
        ) const;

        //- Add using regIOobject information obtained from surface
        template<class GeoMeshType>
        bool addDimField
        (
            vtkMultiPieceDataSet* multiPiece,
            const polySurface* surf,
            const word& fieldName
        ) const;


318 319 320 321 322 323
        //- No copy construct
        surface(const surface&) = delete;

        //- No copy assignment
        void operator=(const surface&) = delete;

324 325 326 327

public:

    //- Run-time type information
328
    TypeNameNoDebug("surface");
329 330 331 332 333 334 335 336 337 338 339 340


    // Declare run-time constructor selection table

        declareRunTimeSelectionTable
        (
            autoPtr,
            surface,
            dictionary,
            (
                const runTimePostProcessing& parent,
                const dictionary& dict,
341
                const HashPtrTable<Function1<vector>>& colours
342 343 344 345 346 347 348 349 350 351 352 353
            ),
            (parent, dict, colours)
        );


    // Constructors

        //- Construct from dictionary
        surface
        (
            const runTimePostProcessing& parent,
            const dictionary& dict,
354
            const HashPtrTable<Function1<vector>>& colours
355 356 357 358 359
        );


    // Selectors

360
        //- Return selected surface
361 362 363 364
        static autoPtr<surface> New
        (
            const runTimePostProcessing& parent,
            const dictionary& dict,
365
            const HashPtrTable<Function1<vector>>& colours,
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
            const word& surfaceName
        );


    //- Destructor
    virtual ~surface();


    // Member Functions

        //- Update the actors
        virtual void updateActors(const scalar position);
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

383 384
} // End namespace runTimePostPro
} // End namespace functionObjects
385 386 387 388
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

389 390 391 392 393 394
#ifdef NoRepository
    #include "surfaceTemplates.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

395 396 397
#endif

// ************************************************************************* //