Skip to content

Commit

Permalink
Make core/internal.hpp a private header
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kamaev committed Apr 1, 2013
1 parent d62bc8c commit 5170620
Show file tree
Hide file tree
Showing 54 changed files with 364 additions and 264 deletions.
48 changes: 48 additions & 0 deletions apps/traincascade/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@
#include <queue>
#include "cxmisc.h"

#include "cvconfig.h"
#ifdef HAVE_TBB
# include "tbb/tbb_stddef.h"
# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
# include "tbb/tbb.h"
# include "tbb/task.h"
# undef min
# undef max
# else
# undef HAVE_TBB
# endif
#endif

#ifdef HAVE_TBB
typedef tbb::blocked_range<int> BlockedRange;

template<typename Body> static inline
void parallel_for( const BlockedRange& range, const Body& body )
{
tbb::parallel_for(range, body);
}
#else
class BlockedRange
{
public:
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
int begin() const { return _begin; }
int end() const { return _end; }
int grainsize() const { return _grainsize; }

protected:
int _begin, _end, _grainsize;
};

template<typename Body> static inline
void parallel_for( const BlockedRange& range, const Body& body )
{
body(range);
}
#endif

using namespace std;

static inline double
Expand All @@ -26,6 +68,12 @@ class LessThanIdx
const T* arr;
};

static inline int cvAlign( int size, int align )
{
CV_DbgAssert( (align & (align-1)) == 0 && size < INT_MAX );
return (size + align - 1) & -align;
}

#define CV_THRESHOLD_EPS (0.00001F)

static const int MinBlockSize = 1 << 16;
Expand Down
2 changes: 1 addition & 1 deletion cmake/OpenCVModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ macro(ocv_create_module)
if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$")
if(hdr2 MATCHES "^(opencv2/.*)[^/]+.h(..)?$" AND NOT hdr2 MATCHES "opencv2/${the_module}/private.*")
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main)
endif()
endforeach()
Expand Down
4 changes: 3 additions & 1 deletion include/opencv/cxmisc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __OPENCV_OLD_CXMISC_H__
#define __OPENCV_OLD_CXMISC_H__

#include "opencv2/core/internal.hpp"
#ifdef __cplusplus
# include "opencv2/core/utility.hpp"
#endif

#endif
5 changes: 4 additions & 1 deletion modules/calib3d/perf/perf_pnp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "perf_precomp.hpp"
#include "opencv2/core/internal.hpp"

#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif

using namespace std;
using namespace cv;
Expand Down
8 changes: 1 addition & 7 deletions modules/calib3d/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@
#ifndef __OPENCV_PRECOMP_H__
#define __OPENCV_PRECOMP_H__

#ifdef HAVE_CVCONFIG_H
#include "cvconfig.h"
#endif

#include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/features2d.hpp"

#include "opencv2/core/utility.hpp"
#include "opencv2/core/internal.hpp"

#include <vector>
#include "opencv2/core/private.hpp"

#ifdef HAVE_TEGRA_OPTIMIZATION
#include "opencv2/calib3d/calib3d_tegra.hpp"
Expand Down
5 changes: 4 additions & 1 deletion modules/calib3d/test/test_solvepnp_ransac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/core/internal.hpp"

#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif

using namespace cv;
using namespace std;
Expand Down
8 changes: 2 additions & 6 deletions modules/contrib/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@
#ifndef __OPENCV_PRECOMP_H__
#define __OPENCV_PRECOMP_H__

#ifdef HAVE_CVCONFIG_H
#include "cvconfig.h"
#endif

#include "opencv2/contrib.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"

#include "opencv2/core/utility.hpp"
#include "opencv2/core/internal.hpp"

#include "opencv2/core/private.hpp"

namespace cv
{
Expand Down
1 change: 0 additions & 1 deletion modules/contrib/src/rgbdodometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include <iostream>
#include <limits>

#include "opencv2/core/internal.hpp"
#if defined(HAVE_EIGEN) && EIGEN_WORLD_VERSION == 3
# ifdef ANDROID
template <typename Scalar> Scalar log2(Scalar v) { return std::log(v)/std::log(Scalar(2)); }
Expand Down
101 changes: 0 additions & 101 deletions modules/core/include/opencv2/core/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,107 +808,6 @@ inline FileNode FileStorage::getFirstTopLevelNode() const
return it != r.end() ? *it : FileNode();
}

//////////////////////////////////////// Various algorithms ////////////////////////////////////



// This function splits the input sequence or set into one or more equivalence classes and
// returns the vector of labels - 0-based class indexes for each element.
// predicate(a,b) returns true if the two sequence elements certainly belong to the same class.
//
// The algorithm is described in "Introduction to Algorithms"
// by Cormen, Leiserson and Rivest, the chapter "Data structures for disjoint sets"
template<typename _Tp, class _EqPredicate> int
partition( const std::vector<_Tp>& _vec, std::vector<int>& labels,
_EqPredicate predicate=_EqPredicate())
{
int i, j, N = (int)_vec.size();
const _Tp* vec = &_vec[0];

const int PARENT=0;
const int RANK=1;

std::vector<int> _nodes(N*2);
int (*nodes)[2] = (int(*)[2])&_nodes[0];

// The first O(N) pass: create N single-vertex trees
for(i = 0; i < N; i++)
{
nodes[i][PARENT]=-1;
nodes[i][RANK] = 0;
}

// The main O(N^2) pass: merge connected components
for( i = 0; i < N; i++ )
{
int root = i;

// find root
while( nodes[root][PARENT] >= 0 )
root = nodes[root][PARENT];

for( j = 0; j < N; j++ )
{
if( i == j || !predicate(vec[i], vec[j]))
continue;
int root2 = j;

while( nodes[root2][PARENT] >= 0 )
root2 = nodes[root2][PARENT];

if( root2 != root )
{
// unite both trees
int rank = nodes[root][RANK], rank2 = nodes[root2][RANK];
if( rank > rank2 )
nodes[root2][PARENT] = root;
else
{
nodes[root][PARENT] = root2;
nodes[root2][RANK] += rank == rank2;
root = root2;
}
CV_Assert( nodes[root][PARENT] < 0 );

int k = j, parent;

// compress the path from node2 to root
while( (parent = nodes[k][PARENT]) >= 0 )
{
nodes[k][PARENT] = root;
k = parent;
}

// compress the path from node to root
k = i;
while( (parent = nodes[k][PARENT]) >= 0 )
{
nodes[k][PARENT] = root;
k = parent;
}
}
}
}

// Final O(N) pass: enumerate classes
labels.resize(N);
int nclasses = 0;

for( i = 0; i < N; i++ )
{
int root = i;
while( nodes[root][PARENT] >= 0 )
root = nodes[root][PARENT];
// re-use the rank as the class label
if( nodes[root][RANK] >= 0 )
nodes[root][RANK] = ~nclasses++;
labels[i] = ~nodes[root][RANK];
}

return nclasses;
}


//////////////////////////////////////////////////////////////////////////////

class CV_EXPORTS Formatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace cv
}



/****************************************************************************************\
* Common declarations *
\****************************************************************************************/
Expand Down Expand Up @@ -187,6 +188,8 @@ static inline cv::Size cvGetMatSize( const CvMat* mat )
return cv::Size(mat->cols, mat->rows);
}



/****************************************************************************************\
* Structures and macros for integration with IPP *
\****************************************************************************************/
Expand Down Expand Up @@ -245,4 +248,111 @@ typedef enum CvStatus
}
CvStatus;



/****************************************************************************************\
* Auxiliary algorithms *
\****************************************************************************************/

namespace cv
{

// This function splits the input sequence or set into one or more equivalence classes and
// returns the vector of labels - 0-based class indexes for each element.
// predicate(a,b) returns true if the two sequence elements certainly belong to the same class.
//
// The algorithm is described in "Introduction to Algorithms"
// by Cormen, Leiserson and Rivest, the chapter "Data structures for disjoint sets"
template<typename _Tp, class _EqPredicate> int
partition( const std::vector<_Tp>& _vec, std::vector<int>& labels,
_EqPredicate predicate=_EqPredicate())
{
int i, j, N = (int)_vec.size();
const _Tp* vec = &_vec[0];

const int PARENT=0;
const int RANK=1;

std::vector<int> _nodes(N*2);
int (*nodes)[2] = (int(*)[2])&_nodes[0];

// The first O(N) pass: create N single-vertex trees
for(i = 0; i < N; i++)
{
nodes[i][PARENT]=-1;
nodes[i][RANK] = 0;
}

// The main O(N^2) pass: merge connected components
for( i = 0; i < N; i++ )
{
int root = i;

// find root
while( nodes[root][PARENT] >= 0 )
root = nodes[root][PARENT];

for( j = 0; j < N; j++ )
{
if( i == j || !predicate(vec[i], vec[j]))
continue;
int root2 = j;

while( nodes[root2][PARENT] >= 0 )
root2 = nodes[root2][PARENT];

if( root2 != root )
{
// unite both trees
int rank = nodes[root][RANK], rank2 = nodes[root2][RANK];
if( rank > rank2 )
nodes[root2][PARENT] = root;
else
{
nodes[root][PARENT] = root2;
nodes[root2][RANK] += rank == rank2;
root = root2;
}
CV_Assert( nodes[root][PARENT] < 0 );

int k = j, parent;

// compress the path from node2 to root
while( (parent = nodes[k][PARENT]) >= 0 )
{
nodes[k][PARENT] = root;
k = parent;
}

// compress the path from node to root
k = i;
while( (parent = nodes[k][PARENT]) >= 0 )
{
nodes[k][PARENT] = root;
k = parent;
}
}
}
}

// Final O(N) pass: enumerate classes
labels.resize(N);
int nclasses = 0;

for( i = 0; i < N; i++ )
{
int root = i;
while( nodes[root][PARENT] >= 0 )
root = nodes[root][PARENT];
// re-use the rank as the class label
if( nodes[root][RANK] >= 0 )
nodes[root][RANK] = ~nclasses++;
labels[i] = ~nodes[root][RANK];
}

return nclasses;
}

} // namespace cv

#endif // __OPENCV_CORE_PRIVATE_HPP__
Loading

0 comments on commit 5170620

Please sign in to comment.