C++ (Cpp) waveform_type Example

Introduction

The c++ (cpp) waveform_type example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: waveform_type

Example#1

 waveform_averager( const waveform_type& t ) : size_( t.size() )
                                             , actualAverages_( 1 )
                                             , data_( new lvalue_type[ size_ ] ) {
     std::copy( t.begin(), t.end(), data_.get() );            
 }

Example#2
File: find_threshold_timepoints.hppProject: qtplatz/qtplatz

        void operator () ( const waveform_type& data
                           , adportable::counting::counting_result& result
                           , std::vector< double >& processed ) {

            const bool findUp = method.slope == adcontrols::threshold_method::CrossUp;
            const unsigned int nfilter = static_cast<unsigned int>( method.response_time / data.meta_.xIncrement ) | 01;

            double level;
            if ( method.use_filter ) {
                waveform_type::apply_filter( processed, data, method );
                level = method.threshold_level;
            } else {
                level = int( ( method.threshold_level + data.meta_.scaleOffset ) / data.meta_.scaleFactor );
            }

            result.set_algo( static_cast< enum adportable::counting::algo >( method.algo_ ) );
            result.set_threshold_level( method.threshold_level );

            auto& elements = result.indices2();

            adportable::counting::threshold_finder finder( findUp, nfilter );

            const bool average( method.algo_ == adcontrols::threshold_method::AverageRelative );
            adportable::stddev stddev;

            if ( ranges.enable() ) {

                using adcontrols::CountingMethod;

                for ( const auto& v: ranges ) {
                    if ( std::get< CountingMethod::CountingEnable >( v ) ) {
                        const auto& time_range = std::get< CountingMethod::CountingRange >( v ); // center, width
                        auto offs = waveform_horizontal().range( data.method_, data.meta_, time_range );
                        if ( offs.second ) {
                            size_t eoffs = offs.first + offs.second;

                            if ( average ) {
                                if ( method.use_filter ) {
                                    auto sd = stddev( processed.begin() + offs.first, offs.second );
                                    finder( processed.begin(), processed.begin() + eoffs, elements, level + sd.second, offs.first );
                                } else if ( data.meta_.dataType == 1 ) {
                                    auto sd = stddev( data.template begin<int16_t>() + offs.first, offs.second );
                                    finder( data.template begin<int8_t>(), data.template begin< int8_t >() + eoffs, elements, level + sd.second, offs.first );
                                } else if ( data.meta_.dataType == 2 ) {
                                    auto sd = stddev( data.template begin<int16_t>() + offs.first, offs.second );
                                    finder( data.template begin<int16_t>(), data.template begin< int16_t >() + eoffs, elements, level + sd.second, offs.first );
                                } else if ( data.meta_.dataType == 4 ) {
                                    auto sd = stddev( data.template begin<int32_t>() + offs.first, offs.second );
                                    finder( data.template begin<int32_t>(), data.template begin<int32_t>() + eoffs, elements, level + sd.second, offs.first );
                                }
                            } else {
                                if ( method.use_filter ) {
                                    finder( processed.begin(), processed.begin() + eoffs, elements, level, offs.first );
                                } else if ( data.meta_.dataType == 1 ) {
                                    finder( data.template begin<int8_t>(), data.template begin< int8_t >() + eoffs, elements, level, offs.first );
                                } else if ( data.meta_.dataType == 2 ) {
                                    finder( data.template begin<int16_t>(), data.template begin< int16_t >() + eoffs, elements, level, offs.first );
                                } else if ( data.meta_.dataType == 4 ) {
                                    finder( data.template begin<int32_t>(), data.template begin<int32_t>() + eoffs, elements, level, offs.first );
                                }
                            }
                        }
                    }
                }

            } else {

                if ( average ) {
                    if ( method.use_filter ) {
                        auto sd = stddev( processed.begin(), processed.size() );
                        finder( processed.begin(), processed.end(), elements, level + sd.second, 0 );
                    } else if ( data.meta_.dataType == 1 ) {
                        auto sd = stddev( data.template begin< int8_t >(), data.size() );
                        finder( data.template begin<int8_t>(), data.template end<int8_t>(), elements, level + sd.second );
                    } else if ( data.meta_.dataType == 2 ) {
                        auto sd = stddev( data.template begin< int16_t >(), data.size() );
                        finder( data.template begin<int16_t>(), data.template end<int16_t>(), elements, level + sd.second );
                    } else if ( data.meta_.dataType == 4 ) {
                        auto sd = stddev( data.template begin< int32_t >(), data.size() );
                        finder( data.template begin<int32_t>(), data.template end<int32_t>(), elements, level + sd.second );
                    }
                } else {
                    if ( method.use_filter ) {
                        finder( processed.begin(), processed.end(), elements, level, 0 );
                    } else if ( data.meta_.dataType == 1 ) {
                        finder( data.template begin<int8_t>(), data.template end<int8_t>(), elements, level );
                    } else if ( data.meta_.dataType == 2 ) {
                        finder( data.template begin<int16_t>(), data.template end<int16_t>(), elements, level );
                    } else if ( data.meta_.dataType == 4 ) {
                        finder( data.template begin<int32_t>(), data.template end<int32_t>(), elements, level );
                    }
                }
            }
        }