rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
Map3D< TColNum, TRowNum, TValue, TXColumn, TRow > Class Template Reference

#include <table_helper.h>

Inheritance diagram for Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >:
Inheritance graph
[legend]
Collaboration diagram for Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >:
Collaboration graph
[legend]

Public Member Functions

 Map3D (const char *name)
 
template<typename TValueInit , typename TXColumnInit , typename TRowInit >
void initTable (TValueInit(&table)[TRowNum][TColNum], const TXColumnInit(&columnBins)[TColNum], const TRowInit(&rowBins)[TRowNum])
 
float getValue (float xColumn, float yRow) const final
 
void setAll (TValue value)
 

Private Member Functions

template<int TMult, int TDiv>
void initValues (scaled_channel< TValue, TMult, TDiv >(&table)[TRowNum][TColNum])
 
void initValues (TValue(&table)[TRowNum][TColNum])
 
template<int TRowMult, int TRowDiv>
void initRows (const scaled_channel< TRow, TRowMult, TRowDiv >(&rowBins)[TRowNum])
 
void initRows (const TRow(&rowBins)[TRowNum])
 
template<int TColMult, int TColDiv>
void initCols (const scaled_channel< TXColumn, TColMult, TColDiv >(&columnBins)[TColNum])
 
void initCols (const TXColumn(&columnBins)[TColNum])
 
TValue getValueAtPosition (size_t row, size_t column) const
 

Static Private Member Functions

static size_t getIndexForCoordinates (size_t row, size_t column)
 

Private Attributes

TValue(* m_values )[TRowNum][TColNum] = nullptr
 
const TRow(* m_rowBins )[TRowNum] = nullptr
 
const TXColumn(* m_columnBins )[TColNum] = nullptr
 
float m_rowMult = 1
 
float m_colMult = 1
 
float m_valueMult = 1
 
const charm_name
 

Detailed Description

template<int TColNum, int TRowNum, typename TValue, typename TXColumn, typename TRow>
class Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >

this helper class brings together 3D table with two 2D axis curves TODO: explicitly spell out why do we have this template and when exactly is it useful (useful with scaled content?) todo: improve interpolate3d to handle scaling? A recommended use is if a class depends on a table and this can be shared with several classes but only one is instantiated, see for example airmass.h It can also be used if you need to test the behavior of a calculated X/Y => table value, but it is advisable to do those expects externally and/or only test the result of the get, since interpotalate3d is easier to use and does not require initiation. *** WARNING *** https://en.wikipedia.org/wiki/KISS_principle *** WARNING *** this helper requires initialization, make sure that helper is useful any time you consider using it *** WARNING *** we had too many bugs where we were not initializing, often just using the underlying interpolate3d is the way to go

Definition at line 43 of file table_helper.h.

Constructor & Destructor Documentation

◆ Map3D()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::Map3D ( const char name)
inline

Definition at line 45 of file table_helper.h.

45 {
46 m_name = name;
47 }
const char * m_name

Member Function Documentation

◆ getIndexForCoordinates()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
static size_t Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::getIndexForCoordinates ( size_t  row,
size_t  column 
)
inlinestaticprivate

Definition at line 115 of file table_helper.h.

115 {
116 // Index 0 is bottom left corner
117 // Index TColNum - 1 is bottom right corner
118 // indicies count right, then up
119 return row * TColNum + column;
120 }

Referenced by Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::getValueAtPosition().

Here is the caller graph for this function:

◆ getValue()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
float Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::getValue ( float  xColumn,
float  yRow 
) const
inlinefinalvirtual

Implements ValueProvider3D.

Definition at line 59 of file table_helper.h.

59 {
60 if (!m_values) {
61 criticalError("Access to uninitialized table: %s", m_name);
62 return 0;
63 }
64
65 return interpolate3d(*m_values,
66 *m_rowBins, yRow * m_rowMult,
67 *m_columnBins, xColumn * m_colMult) *
69 }
float m_rowMult
const TXColumn(* m_columnBins)[TColNum]
float m_valueMult
float m_colMult
TValue(* m_values)[TRowNum][TColNum]
const TRow(* m_rowBins)[TRowNum]

◆ getValueAtPosition()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
TValue Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::getValueAtPosition ( size_t  row,
size_t  column 
) const
inlineprivate

Definition at line 122 of file table_helper.h.

122 {
123 auto idx = getIndexForCoordinates(row, column);
124 return m_values[idx];
125 }
static size_t getIndexForCoordinates(size_t row, size_t column)
Here is the call graph for this function:

◆ initCols() [1/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
template<int TColMult, int TColDiv>
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initCols ( const scaled_channel< TXColumn, TColMult, TColDiv >(&)  columnBins[TColNum])
inlineprivate

Definition at line 105 of file table_helper.h.

105 {
106 m_columnBins = reinterpret_cast<const TXColumn (*)[TColNum]>(&columnBins);
108 }
static constexpr float asFloat()
Definition efi_ratio.h:13

Referenced by Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initCols() [2/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initCols ( const TXColumn(&)  columnBins[TColNum])
inlineprivate

Definition at line 110 of file table_helper.h.

110 {
111 m_columnBins = &columnBins;
112 m_colMult = 1;
113 }

◆ initRows() [1/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
template<int TRowMult, int TRowDiv>
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initRows ( const scaled_channel< TRow, TRowMult, TRowDiv >(&)  rowBins[TRowNum])
inlineprivate

Definition at line 94 of file table_helper.h.

94 {
95 m_rowBins = reinterpret_cast<const TRow (*)[TRowNum]>(&rowBins);
97 }

Referenced by Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initRows() [2/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initRows ( const TRow(&)  rowBins[TRowNum])
inlineprivate

Definition at line 99 of file table_helper.h.

99 {
100 m_rowBins = &rowBins;
101 m_rowMult = 1;
102 }

◆ initTable()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
template<typename TValueInit , typename TXColumnInit , typename TRowInit >
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initTable ( TValueInit(&)  table[TRowNum][TColNum],
const TXColumnInit(&)  columnBins[TColNum],
const TRowInit(&)  rowBins[TRowNum] 
)
inline

Definition at line 49 of file table_helper.h.

50 {
51 // This splits out here so that we don't need one overload of init per possible combination of table/rows/columns types/dimensions
52 // Overload resolution figures out the correct versions of the functions below to call, some of which have assertions about what's allowed
53 initValues(table);
54 initRows(rowBins);
55 initCols(columnBins);
56 }
void initCols(const scaled_channel< TXColumn, TColMult, TColDiv >(&columnBins)[TColNum])
void initValues(scaled_channel< TValue, TMult, TDiv >(&table)[TRowNum][TColNum])
void initRows(const scaled_channel< TRow, TRowMult, TRowDiv >(&rowBins)[TRowNum])

Referenced by initElectronicThrottle(), initFuelMap(), initGpPwm(), initScriptImpl(), initSpeedDensity(), and initVvtActuators().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initValues() [1/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
template<int TMult, int TDiv>
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initValues ( scaled_channel< TValue, TMult, TDiv >(&)  table[TRowNum][TColNum])
inlineprivate

Definition at line 83 of file table_helper.h.

83 {
84 m_values = reinterpret_cast<TValue (*)[TRowNum][TColNum]>(&table);
86 }

Referenced by Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initValues() [2/2]

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::initValues ( TValue(&)  table[TRowNum][TColNum])
inlineprivate

Definition at line 88 of file table_helper.h.

88 {
89 m_values = &table;
90 m_valueMult = 1;
91 }

◆ setAll()

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
void Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::setAll ( TValue  value)
inline

Definition at line 71 of file table_helper.h.

71 {
72 efiAssertVoid(ObdCode::CUSTOM_ERR_6573, m_values, "map not initialized");
73
74 for (size_t r = 0; r < TRowNum; r++) {
75 for (size_t c = 0; c < TColNum; c++) {
76 (*m_values)[r][c] = value / m_valueMult;
77 }
78 }
79 }
@ CUSTOM_ERR_6573

Field Documentation

◆ m_colMult

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
float Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_colMult = 1
private

◆ m_columnBins

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
const TXColumn(* Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_columnBins)[TColNum] = nullptr
private

◆ m_name

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
const char* Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_name
private

◆ m_rowBins

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
const TRow(* Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_rowBins)[TRowNum] = nullptr
private

◆ m_rowMult

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
float Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_rowMult = 1
private

◆ m_valueMult

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
float Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_valueMult = 1
private

◆ m_values

template<int TColNum, int TRowNum, typename TValue , typename TXColumn , typename TRow >
TValue(* Map3D< TColNum, TRowNum, TValue, TXColumn, TRow >::m_values)[TRowNum][TColNum] = nullptr
private

The documentation for this class was generated from the following file: