当前位置: 首页>>代码示例>>C++>>正文


C++ vector_type::resize方法代码示例

本文整理汇总了C++中vector_type::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ vector_type::resize方法的具体用法?C++ vector_type::resize怎么用?C++ vector_type::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vector_type的用法示例。


在下文中一共展示了vector_type::resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: super

    decorated_tuple(cow_pointer_type d, size_t offset)
        : super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) {
#       ifdef CPPA_DEBUG
        const cow_pointer_type& ptr = m_decorated; // prevent detaching
#       endif
        CPPA_REQUIRE((ptr->size() - offset) >= sizeof...(ElementTypes));
        CPPA_REQUIRE(offset > 0);
        size_t i = offset;
        m_mapping.resize(sizeof...(ElementTypes));
        std::generate(m_mapping.begin(), m_mapping.end(), [&]() {return i++;});
    }
开发者ID:alepharchives,项目名称:libcppa,代码行数:11,代码来源:decorated_tuple.hpp

示例2: init_vector_type

 static void init_vector_type( vector_type &x ) { x.resize( 2 * n ); }
开发者ID:Ambrosys,项目名称:molecular_dynamics_js,代码行数:1,代码来源:molecular_dynamics.cpp

示例3: read_vtk

    bool read_vtk ( int grid_form, const std::string &file_name, vector_type &p, vector_type &v, vector_type &f )
    {
        typedef typename vector_type::value_type real_type;
        typedef typename vector_type::size_type  index_type;

        switch ( grid_form )
        {

            case 0:
            {
                vtkXMLUnstructuredGridReader *reader = vtkXMLUnstructuredGridReader::New();
                reader->SetFileName ( file_name.c_str() );
                reader->Update();
                vtkUnstructuredGrid *vtk_grid = reader->GetOutput();
                vtk_grid->Update();

                vtkDoubleArray* velocities = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "velocities" ) );
                vtkDoubleArray* forces = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "forces" ) );

                index_type size = 3*vtk_grid->GetNumberOfPoints();
                p.resize ( size );
                v.resize ( size );
                f.resize ( size );
                for ( vtkIdType i = 0,j = 0; i < vtk_grid->GetNumberOfPoints(), j < size; ++i, j+=3 )
                {
                    // Set Positions
                    real_type * tuple = vtk_grid->GetPoint ( i );
                    p ( j ) = tuple[0];
                    p ( j+1 ) = tuple[1];
                    p ( j+2 ) = tuple[2];
                    // Set Velocities
                    velocities->GetTupleValue ( i, tuple );
                    v ( j ) = tuple[0];
                    v ( j+1 ) = tuple[1];
                    v ( j+2 ) = tuple[2];
                    // Set Forces
                    forces->GetTupleValue ( i, tuple );
                    f ( j ) = tuple[0];
                    f ( j+1 ) = tuple[1];
                    f ( j+2 ) = tuple[2];
                }
                reader->Delete();

                break;
            }

            case 1:
            {
                vtkXMLStructuredGridReader *reader = vtkXMLStructuredGridReader::New();
                reader->SetFileName ( file_name.c_str() );
                reader->Update();
                vtkStructuredGrid *vtk_grid = reader->GetOutput();
                vtk_grid->Update();

                vtkDoubleArray* velocities = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "velocities" ) );
                vtkDoubleArray* forces = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "forces" ) );

                index_type size = 3*vtk_grid->GetNumberOfPoints();
                p.resize ( size );
                v.resize ( size );
                f.resize ( size );
                for ( vtkIdType i = 0,j = 0; i < vtk_grid->GetNumberOfPoints(), j < size; ++i, j+=3 )
                {
                    // Set Positions
                    real_type * tuple = vtk_grid->GetPoint ( i );
                    p ( j ) = tuple[0];
                    p ( j+1 ) = tuple[1];
                    p ( j+2 ) = tuple[2];
                    // Set Velocities
                    velocities->GetTupleValue ( i, tuple );
                    v ( j ) = tuple[0];
                    v ( j+1 ) = tuple[1];
                    v ( j+2 ) = tuple[2];
                    // Set Forces
                    forces->GetTupleValue ( i, tuple );
                    f ( j ) = tuple[0];
                    f ( j+1 ) = tuple[1];
                    f ( j+2 ) = tuple[2];
                }
                reader->Delete();

                break;
            }

            default:
            {
                std::cerr << "Grid type not implemented." << std::endl;
                return 0;
            }
        }

        return 1;

    }
开发者ID:macundo,项目名称:moops,代码行数:94,代码来源:read_vtk.hpp


注:本文中的vector_type::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。