@@ -93,7 +93,7 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
9393 plot.m_inMax , plot.m_outMax , plot.m_outMin ) + plot.m_offsetY );
9494
9595 cv::line (*m_image, previousPoint, currentPoint, plot.m_color ,
96- plot.m_tickness , cv::LINE_8);
96+ plot.m_tickness , cv::LINE_8);
9797 }
9898 }
9999 // 2D vector drawing.
@@ -117,30 +117,26 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
117117 cv::Scalar color, int thickness)
118118 {
119119 // Check if id is already contained.
120- for (const int & i : m_ids )
120+ for (const auto & pair : m_plots )
121121 {
122+ const int & i = pair.first ;
122123 if (i == id)
123124 {
124125 // Remove plot from list.
125- std::list<Plot2D>::iterator it = m_plots.begin ();
126- std::advance (it, id);
127- m_plots.erase (it);
128-
129- // Remove id from list.
130- auto removeIndex = std::remove (m_ids.begin (), m_ids.end (), id);
131- m_ids.erase (removeIndex, m_ids.end ());
126+ auto it = m_plots.find (i);
127+ if (it != m_plots.end ())
128+ m_plots.erase (it);
132129 }
133130 }
134-
135- m_ids.push_back (id);
136-
131+
137132 // Add ploting object to list.
138133 std::vector<double > doubles;
139134 for (int i =0 ;i<points.size (); i++)
140135 {
141136 doubles.push_back (static_cast <double >(points[i]));
142137 }
143- m_plots.emplace_back (Plot2D (doubles, id, start, end, color, thickness));
138+
139+ m_plots.insert (std::make_pair (id, Plot2D (doubles, id, start, end, color, thickness)));
144140
145141 }
146142
@@ -149,23 +145,18 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
149145 cv::Scalar color, int thickness)
150146{
151147 // Check if id is already contained.
152- for (const int & i : m_ids )
148+ for (const auto & pair : m_plots )
153149 {
150+ const int & i = pair.first ;
154151 if (i == id)
155152 {
156153 // Remove plot from list.
157- std::list<Plot2D>::iterator it = m_plots.begin ();
158- std::advance (it, id);
159- m_plots.erase (it);
160-
161- // Remove id from list.
162- auto removeIndex = std::remove (m_ids.begin (), m_ids.end (), id);
163- m_ids.erase (removeIndex, m_ids.end ());
154+ auto it = m_plots.find (i);
155+ if (it != m_plots.end ())
156+ m_plots.erase (it);
164157 }
165158 }
166159
167- m_ids.push_back (id);
168-
169160 // Convert points vector to double.
170161 std::vector<std::vector<double >> doubles;
171162 std::vector<double > temp (2 );
@@ -178,7 +169,7 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
178169 }
179170
180171 // Add ploting object to list.
181- m_plots.emplace_back ( Plot2D (doubles, id, start, end, color, thickness));
172+ m_plots.insert ( std::make_pair (id, Plot2D (doubles, id, start, end, color, thickness) ));
182173
183174}
184175
@@ -200,8 +191,8 @@ void cr::utils::Plot::clean()
200191 cv::line (*m_image, cv::Point (i, 0 ),
201192 cv::Point (i, m_height), cv::Scalar (0 , 0 , 0 ));
202193
194+ // Clear all instances from container.
203195 m_plots.clear ();
204- m_ids.clear ();
205196}
206197
207198void cr::utils::Plot::show ()
@@ -225,9 +216,10 @@ void cr::utils::Plot::show()
225216 cv::Point (i, m_height), cv::Scalar (0 , 0 , 0 ));
226217 }
227218
228- // Draw plot objects on window.
229- for (const Plot2D& plot : m_plots)
219+ // Iterate over the values (Plot2D instances) in the map
220+ for (const auto & pair : m_plots)
230221 {
222+ const Plot2D& plot = pair.second ;
231223 renderPlot (plot);
232224 }
233225
0 commit comments