LCOV - code coverage report
Current view: top level - src/mesquite/Mesh - MeshImplTags.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 23 27 85.2 %
Date: 2020-07-18 00:09:26 Functions: 13 14 92.9 %
Branches: 7 20 35.0 %

           Branch data     Line data    Source code
       1                 :            : /* *****************************************************************
       2                 :            :     MESQUITE -- The Mesh Quality Improvement Toolkit
       3                 :            : 
       4                 :            :     Copyright 2004 Lawrence Livermore National Laboratory.  Under
       5                 :            :     the terms of Contract B545069 with the University of Wisconsin --
       6                 :            :     Madison, Lawrence Livermore National Laboratory retains certain
       7                 :            :     rights in this software.
       8                 :            : 
       9                 :            :     This library is free software; you can redistribute it and/or
      10                 :            :     modify it under the terms of the GNU Lesser General Public
      11                 :            :     License as published by the Free Software Foundation; either
      12                 :            :     version 2.1 of the License, or (at your option) any later version.
      13                 :            : 
      14                 :            :     This library is distributed in the hope that it will be useful,
      15                 :            :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :            :     Lesser General Public License for more details.
      18                 :            : 
      19                 :            :     You should have received a copy of the GNU Lesser General Public License
      20                 :            :     (lgpl.txt) along with this library; if not, write to the Free Software
      21                 :            :     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      22                 :            : 
      23                 :            :     [email protected]
      24                 :            : 
      25                 :            :   ***************************************************************** */
      26                 :            : 
      27                 :            : #ifndef MESQUITE_MESH_IMPL_TAGS_HPP
      28                 :            : #define MESQUITE_MESH_IMPL_TAGS_HPP
      29                 :            : 
      30                 :            : #include "Mesquite.hpp"
      31                 :            : #include "MeshInterface.hpp"
      32                 :            : 
      33                 :            : #include <vector>
      34                 :            : 
      35                 :            : namespace MBMesquite
      36                 :            : {
      37                 :            : 
      38         [ +  - ]:       1022 : struct TagDescription
      39                 :            : {
      40                 :            :     // The VTK attribute type the data was read from, or NONE if not VTK data.
      41                 :            :     // This property is kept only so that when a vtk file is read and subseqquently
      42                 :            :     // written, it can be preserved for other potential readers that actually care
      43                 :            :     // about it.
      44                 :            :     enum VtkType
      45                 :            :     {
      46                 :            :         NONE = 0,
      47                 :            :         SCALAR,
      48                 :            :         COLOR,
      49                 :            :         VECTOR,
      50                 :            :         NORMAL,
      51                 :            :         TEXTURE,
      52                 :            :         TENSOR,
      53                 :            :         FIELD
      54                 :            :     };
      55                 :            : 
      56                 :            :     std::string name;    //!< Tag name
      57                 :            :     Mesh::TagType type;  //!< Tag data type
      58                 :            :     VtkType vtkType;     //!< Attribute type from VTK file
      59                 :            :     size_t size;         //!< Size of tag data (sizeof(type)*array_length)
      60                 :            :     std::string member;  //!< Field member name for 1-member fields.
      61                 :            : 
      62                 :         22 :     inline TagDescription( std::string n, Mesh::TagType t, VtkType v, size_t s, std::string m )
      63         [ +  - ]:         22 :         : name( n ), type( t ), vtkType( v ), size( s ), member( m )
      64                 :            :     {
      65                 :         22 :     }
      66                 :            : 
      67         [ +  - ]:        213 :     inline TagDescription() : type( Mesh::BYTE ), vtkType( NONE ), size( 0 ) {}
      68                 :            : 
      69                 :            :     inline bool operator==( const TagDescription& o ) const
      70                 :            :     {
      71                 :            :         return name == o.name && type == o.type && vtkType == o.vtkType && size == o.size;
      72                 :            :     }
      73                 :         14 :     inline bool operator!=( const TagDescription& o ) const
      74                 :            :     {
      75 [ +  - ][ +  - ]:         14 :         return name != o.name || type != o.type || vtkType != o.vtkType || size != o.size;
         [ +  - ][ -  + ]
      76                 :            :     }
      77                 :            : };
      78                 :            : 
      79                 :            : /**\class MeshImplTags
      80                 :            :  *
      81                 :            :  * Store tags and tag data for Mesquite's native mesh representation.
      82                 :            :  * Stores for each tag: properties, element data, and vertex data.
      83                 :            :  * The tag element and vertex data sets are maps between some element
      84                 :            :  * or vertex index and a tag value.
      85                 :            :  */
      86                 :        286 : class MeshImplTags
      87                 :            : {
      88                 :            :   public:
      89                 :        143 :     ~MeshImplTags()
      90                 :        143 :     {
      91                 :        143 :         clear();
      92                 :        143 :     }
      93                 :            : 
      94                 :            :     /** \class TagData
      95                 :            :      * Store data for a single tag
      96                 :            :      */
      97                 :            :     struct TagData
      98                 :            :     {
      99                 :            : 
     100                 :            :         //! tag meta data
     101                 :            :         const TagDescription desc;
     102                 :            : 
     103                 :            :         //! per-element data, or NULL if none has been set.
     104                 :            :         void* elementData;
     105                 :            : 
     106                 :            :         //! number of entries in elementData
     107                 :            :         size_t elementCount;
     108                 :            : 
     109                 :            :         //! per-vertex data, or NULL if none has been set.
     110                 :            :         void* vertexData;
     111                 :            : 
     112                 :            :         //! number of entries in vertexData
     113                 :            :         size_t vertexCount;
     114                 :            : 
     115                 :            :         //! Default value for tag
     116                 :            :         void* defaultValue;
     117                 :            : 
     118                 :            :         /** \brief Construct tag
     119                 :            :          *\param name Tag name
     120                 :            :          *\param type Tag data type
     121                 :            :          *\param length Tag array length (1 for scalar/non-array)
     122                 :            :          *\param default_val Default value for tag
     123                 :            :          *\param vtk_type Attribute type in VTK file
     124                 :            :          */
     125                 :          0 :         inline TagData( const std::string& name, Mesh::TagType type, unsigned length, void* default_val = 0,
     126                 :            :                         TagDescription::VtkType vtk_type = TagDescription::NONE, const std::string& field_member = "" )
     127         [ #  # ]:          0 :             : desc( name, type, vtk_type, length * size_from_tag_type( type ), field_member ), elementData( 0 ),
     128 [ #  # ][ #  # ]:          0 :               elementCount( 0 ), vertexData( 0 ), vertexCount( 0 ), defaultValue( default_val )
     129                 :            :         {
     130                 :          0 :         }
     131                 :            : 
     132                 :            :         /** \brief Construct tag
     133                 :            :          *\param desc Tag description object
     134                 :            :          */
     135                 :        184 :         inline TagData( const TagDescription& descr )
     136                 :        184 :             : desc( descr ), elementData( 0 ), elementCount( 0 ), vertexData( 0 ), vertexCount( 0 ), defaultValue( 0 )
     137                 :            :         {
     138                 :        184 :         }
     139                 :            : 
     140                 :            :         ~TagData();
     141                 :            :     };
     142                 :            : 
     143                 :            :     /** \brief Get the size of the passed data type */
     144                 :            :     static size_t size_from_tag_type( Mesh::TagType type );
     145                 :            : 
     146                 :            :     /** \brief Clear all data */
     147                 :            :     void clear();
     148                 :            : 
     149                 :            :     /** \brief Get tag index from name */
     150                 :            :     size_t handle( const std::string& name, MsqError& err ) const;
     151                 :            : 
     152                 :            :     /** \brief Get tag properties */
     153                 :            :     const TagDescription& properties( size_t tag_handle, MsqError& err ) const;
     154                 :            : 
     155                 :            :     /** \brief Create a new tag
     156                 :            :      *
     157                 :            :      * Create a new tag with the passed properties
     158                 :            :      *\param name Tag name (must be unique)
     159                 :            :      *\param type Tag data type
     160                 :            :      *\param length Number of values in tag (array length, 1 for scalar)
     161                 :            :      *\param defval Optional default value for tag
     162                 :            :      */
     163                 :            :     size_t create( const std::string& name, Mesh::TagType type, unsigned length, const void* defval, MsqError& err );
     164                 :            : 
     165                 :            :     /** \brief Create a new tag
     166                 :            :      *
     167                 :            :      * Create a new tag with the passed properties
     168                 :            :      */
     169                 :            :     size_t create( const TagDescription& desc, const void* defval, MsqError& err );
     170                 :            : 
     171                 :            :     /**\brief Remove a tag */
     172                 :            :     void destroy( size_t tag_index, MsqError& err );
     173                 :            : 
     174                 :            :     /**\brief Set tag data on elements */
     175                 :            :     void set_element_data( size_t tag_handle, size_t num_indices, const size_t* elem_indices, const void* tag_data,
     176                 :            :                            MsqError& err );
     177                 :            : 
     178                 :            :     /**\brief Set tag data on vertices */
     179                 :            :     void set_vertex_data( size_t tag_handle, size_t num_indices, const size_t* elem_indices, const void* tag_data,
     180                 :            :                           MsqError& err );
     181                 :            : 
     182                 :            :     /**\brief Get tag data on elements */
     183                 :            :     void get_element_data( size_t tag_handle, size_t num_indices, const size_t* elem_indices, void* tag_data,
     184                 :            :                            MsqError& err ) const;
     185                 :            : 
     186                 :            :     /**\brief Get tag data on vertices */
     187                 :            :     void get_vertex_data( size_t tag_handle, size_t num_indices, const size_t* elem_indices, void* tag_data,
     188                 :            :                           MsqError& err ) const;
     189                 :            : 
     190                 :            :     /**\class TagIterator
     191                 :            :      *
     192                 :            :      * Iterate over list of valid tag handles
     193                 :            :      */
     194                 :            :     class TagIterator
     195                 :            :     {
     196                 :            :       public:
     197                 :         61 :         TagIterator() : tags( 0 ), index( 0 ) {}
     198                 :        148 :         TagIterator( MeshImplTags* d, size_t i ) : tags( d ), index( i ) {}
     199                 :         39 :         size_t operator*() const
     200                 :            :         {
     201                 :         39 :             return index + 1;
     202                 :            :         }
     203                 :            :         TagIterator operator++();
     204                 :            :         TagIterator operator--();
     205                 :            :         TagIterator operator++( int );
     206                 :            :         TagIterator operator--( int );
     207                 :            :         bool operator==( TagIterator other ) const
     208                 :            :         {
     209                 :            :             return index == other.index;
     210                 :            :         }
     211                 :         74 :         bool operator!=( TagIterator other ) const
     212                 :            :         {
     213                 :         74 :             return index != other.index;
     214                 :            :         }
     215                 :            : 
     216                 :            :       private:
     217                 :            :         MeshImplTags* tags;
     218                 :            :         size_t index;
     219                 :            :     };
     220                 :            :     TagIterator tag_begin();
     221                 :         74 :     TagIterator tag_end()
     222                 :            :     {
     223                 :         74 :         return TagIterator( this, tagList.size() );
     224                 :            :     }
     225                 :            : 
     226                 :            :     /**\brief Check if any vertices have tag */
     227                 :            :     bool tag_has_vertex_data( size_t index, MsqError& err );
     228                 :            :     /**\brief Check if any elements have tag */
     229                 :            :     bool tag_has_element_data( size_t index, MsqError& err );
     230                 :            : 
     231                 :            :   private:
     232                 :            :     friend class MeshImplTags::TagIterator;
     233                 :            : 
     234                 :            :     std::vector< TagData* > tagList;
     235                 :            : };  // class MeshImplTags
     236                 :            : 
     237                 :            : }  // namespace MBMesquite
     238                 :            : 
     239                 :            : #endif

Generated by: LCOV version 1.11