From 3814a276166da3119152bed15ceab463f95e770b Mon Sep 17 00:00:00 2001
From: Hans Johnson <hans-johnson@uiowa.edu>
Date: Sat, 30 Jun 2012 13:34:37 -0500
Subject: [PATCH 4/4] COMP: Remove hidden-virtual function warnings.

---
 modules/core/include/opencv2/core/mat.hpp   |    2 +-
 modules/core/include/opencv2/core/types_c.h |   11 ++++---
 modules/ml/include/opencv2/ml/ml.hpp        |   38 ++++++++++++++++++++++++---
 modules/ml/src/boost.cpp                    |   23 +++++++++++++++-
 modules/ml/src/rtrees.cpp                   |   21 +++++++++++++-
 5 files changed, 81 insertions(+), 14 deletions(-)

diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp
index ccc0257..2625739 100644
--- a/modules/core/include/opencv2/core/mat.hpp
+++ b/modules/core/include/opencv2/core/mat.hpp
@@ -387,7 +387,7 @@ inline Mat::operator CvMat() const
 {
     CV_DbgAssert(dims <= 2);
     CvMat m = cvMat(rows, dims == 1 ? 1 : cols, type(), data);
-    m.step = (int)step[0];
+    //m.step = (int)step[0];
     m.type = (m.type & ~CONTINUOUS_FLAG) | (flags & CONTINUOUS_FLAG);
     return m;
 }
diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h
index cbc7872..df567e5 100644
--- a/modules/core/include/opencv2/core/types_c.h
+++ b/modules/core/include/opencv2/core/types_c.h
@@ -651,6 +651,7 @@ typedef struct CvMat
 {
     int type;
     int step;
+    // This should not be used for pointer offsets int step; It is columns*size of element, we should just use the correct pointer types
 
     /* for internal use only */
     int* refcount;
@@ -658,7 +659,7 @@ typedef struct CvMat
 
     union
     {
-        uchar* ptr;
+        uchar* ptr; /*ptr need to be of type void * so taht they have proper alignment*/
         short* s;
         int* i;
         float* fl;
@@ -774,11 +775,11 @@ CV_INLINE  double  cvmGet( const CvMat* mat, int row, int col )
             (unsigned)col < (unsigned)mat->cols );
 
     if( type == CV_32FC1 )
-        return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
+        return ((float*)(mat->data.fl + (size_t)mat->cols*row))[col];
     else
     {
         assert( type == CV_64FC1 );
-        return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
+        return ((double*)(mat->data.db + (size_t)mat->cols*row))[col];
     }
 }
 
@@ -791,11 +792,11 @@ CV_INLINE  void  cvmSet( CvMat* mat, int row, int col, double value )
             (unsigned)col < (unsigned)mat->cols );
 
     if( type == CV_32FC1 )
-        ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
+        ((float*)(mat->data.fl + (size_t)mat->cols*row))[col] = (float)value;
     else
     {
         assert( type == CV_64FC1 );
-        ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
+        ((double*)(mat->data.db + (size_t)mat->cols*row))[col] = (double)value;
     }
 }
 
diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp
index 8def877..341cd24 100644
--- a/modules/ml/include/opencv2/ml/ml.hpp
+++ b/modules/ml/include/opencv2/ml/ml.hpp
@@ -954,24 +954,38 @@ public:
     CvForestTree();
     virtual ~CvForestTree();
 
-    virtual bool train( CvDTreeTrainData* trainData, const CvMat* _subsample_idx, CvRTrees* forest );
-
     virtual int get_var_count() const {return data ? data->var_count : 0;}
     virtual void read( CvFileStorage* fs, CvFileNode* node, CvRTrees* forest, CvDTreeTrainData* _data );
 
     /* dummy methods to avoid warnings: BEGIN */
+    /* Invalid: Throws assert if it is used */
     virtual bool train( const CvMat* trainData, int tflag,
                         const CvMat* responses, const CvMat* varIdx=0,
                         const CvMat* sampleIdx=0, const CvMat* varType=0,
                         const CvMat* missingDataMask=0,
                         CvDTreeParams params=CvDTreeParams() );
 
+    /* Invalid: Throws assert if it is used */
     virtual bool train( CvDTreeTrainData* trainData, const CvMat* _subsample_idx );
+    /* Invalid: Throws assert if it is used */
+    virtual bool train( CvMLData* trainData, CvDTreeParams params=CvDTreeParams() );
+#ifndef SWIG
+    /* Invalid: Throws assert if it is used */
+    CV_WRAP virtual bool train( const cv::Mat& trainData, int tflag,
+                       const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(),
+                       const cv::Mat& sampleIdx=cv::Mat(), const cv::Mat& varType=cv::Mat(),
+                       const cv::Mat& missingDataMask=cv::Mat(),
+                       CvDTreeParams params=CvDTreeParams() );
+
+#endif
     virtual void read( CvFileStorage* fs, CvFileNode* node );
     virtual void read( CvFileStorage* fs, CvFileNode* node,
                        CvDTreeTrainData* data );
     /* dummy methods to avoid warnings: END */
 
+    /* This is the only valid signature to train the ForestTree */
+    virtual bool train( CvDTreeTrainData* trainData, const CvMat* _subsample_idx, CvRTrees* forest );
+
 protected:
     friend struct cv::ForestTreeBestSplitFinder;
 
@@ -1146,8 +1160,6 @@ public:
     CvBoostTree();
     virtual ~CvBoostTree();
 
-    virtual bool train( CvDTreeTrainData* trainData,
-                        const CvMat* subsample_idx, CvBoost* ensemble );
 
     virtual void scale( double s );
     virtual void read( CvFileStorage* fs, CvFileNode* node,
@@ -1155,18 +1167,36 @@ public:
     virtual void clear();
 
     /* dummy methods to avoid warnings: BEGIN */
+    /* Invalid: Throws assert if it is used */
     virtual bool train( const CvMat* trainData, int tflag,
                         const CvMat* responses, const CvMat* varIdx=0,
                         const CvMat* sampleIdx=0, const CvMat* varType=0,
                         const CvMat* missingDataMask=0,
                         CvDTreeParams params=CvDTreeParams() );
+
+    /* Invalid: Throws assert if it is used */
     virtual bool train( CvDTreeTrainData* trainData, const CvMat* _subsample_idx );
+    /* Invalid: Throws assert if it is used */
+    virtual bool train( CvMLData* trainData, CvDTreeParams params=CvDTreeParams() );
+#ifndef SWIG
+    /* Invalid: Throws assert if it is used */
+    CV_WRAP virtual bool train( const cv::Mat& trainData, int tflag,
+                       const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(),
+                       const cv::Mat& sampleIdx=cv::Mat(), const cv::Mat& varType=cv::Mat(),
+                       const cv::Mat& missingDataMask=cv::Mat(),
+                       CvDTreeParams params=CvDTreeParams() );
+
+#endif
 
     virtual void read( CvFileStorage* fs, CvFileNode* node );
     virtual void read( CvFileStorage* fs, CvFileNode* node,
                        CvDTreeTrainData* data );
     /* dummy methods to avoid warnings: END */
 
+    /* This is the only valid signature to train the ForestTree */
+    virtual bool train( CvDTreeTrainData* trainData,
+                        const CvMat* subsample_idx, CvBoost* ensemble );
+
 protected:
 
     virtual void try_split_node( CvDTreeNode* n );
diff --git a/modules/ml/src/boost.cpp b/modules/ml/src/boost.cpp
index 447a998..121c8ef 100644
--- a/modules/ml/src/boost.cpp
+++ b/modules/ml/src/boost.cpp
@@ -110,7 +110,7 @@ CvBoostTree::train( CvDTreeTrainData* _train_data,
     return do_train( _subsample_idx );
 }
 
-
+/*Invalid: These functions are only here to ensure that the base class methods are not called */
 bool
 CvBoostTree::train( const CvMat*, int, const CvMat*, const CvMat*,
                     const CvMat*, const CvMat*, const CvMat*, CvDTreeParams )
@@ -119,7 +119,6 @@ CvBoostTree::train( const CvMat*, int, const CvMat*, const CvMat*,
     return false;
 }
 
-
 bool
 CvBoostTree::train( CvDTreeTrainData*, const CvMat* )
 {
@@ -127,6 +126,26 @@ CvBoostTree::train( CvDTreeTrainData*, const CvMat* )
     return false;
 }
 
+bool
+CvBoostTree::train( CvMLData* , CvDTreeParams)
+{
+    assert(0);
+    return false;
+}
+
+#ifndef SWIG
+CV_WRAP bool
+CvBoostTree::train( const cv::Mat& , int ,
+                     const cv::Mat& , const cv::Mat& ,
+                     const cv::Mat& , const cv::Mat& ,
+                     const cv::Mat& ,
+                     CvDTreeParams )
+{
+    assert(0);
+    return false;
+}
+#endif
+
 
 void
 CvBoostTree::scale( double _scale )
diff --git a/modules/ml/src/rtrees.cpp b/modules/ml/src/rtrees.cpp
index d88611b..0a44ed0 100644
--- a/modules/ml/src/rtrees.cpp
+++ b/modules/ml/src/rtrees.cpp
@@ -64,7 +64,7 @@ bool CvForestTree::train( CvDTreeTrainData* _data,
     return do_train(_subsample_idx);
 }
 
-
+/*Invalid: These functions are only here to ensure that the base class methods are not called */
 bool
 CvForestTree::train( const CvMat*, int, const CvMat*, const CvMat*,
                     const CvMat*, const CvMat*, const CvMat*, CvDTreeParams )
@@ -73,7 +73,6 @@ CvForestTree::train( const CvMat*, int, const CvMat*, const CvMat*,
     return false;
 }
 
-
 bool
 CvForestTree::train( CvDTreeTrainData*, const CvMat* )
 {
@@ -81,7 +80,25 @@ CvForestTree::train( CvDTreeTrainData*, const CvMat* )
     return false;
 }
 
+bool
+CvForestTree::train( CvMLData* , CvDTreeParams)
+{
+    assert(0);
+    return false;
+}
 
+#ifndef SWIG
+CV_WRAP bool
+CvForestTree::train( const cv::Mat& , int ,
+                     const cv::Mat& , const cv::Mat& ,
+                     const cv::Mat& , const cv::Mat& ,
+                     const cv::Mat& ,
+                     CvDTreeParams )
+{
+    assert(0);
+    return false;
+}
+#endif
 
 namespace cv
 {
-- 
1.7.6.1

