mirror of
https://github.com/opencv/opencv.git
synced 2025-06-17 15:20:51 +08:00
Cleaner code for hierarchical_clustering
This commit is contained in:
parent
e4d573a080
commit
bc221bdb90
@ -404,34 +404,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~HierarchicalClusteringIndex()
|
virtual ~HierarchicalClusteringIndex()
|
||||||
{
|
{
|
||||||
free_elements();
|
|
||||||
|
|
||||||
if (root!=NULL) {
|
if (root!=NULL) {
|
||||||
delete[] root;
|
delete[] root;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indices!=NULL) {
|
if (indices!=NULL) {
|
||||||
|
free_indices();
|
||||||
delete[] indices;
|
delete[] indices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Release the inner elements of indices[]
|
|
||||||
*/
|
|
||||||
void free_elements()
|
|
||||||
{
|
|
||||||
if (indices!=NULL) {
|
|
||||||
for(int i=0; i<trees_; ++i) {
|
|
||||||
if (indices[i]!=NULL) {
|
|
||||||
delete[] indices[i];
|
|
||||||
indices[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns size of index.
|
* Returns size of index.
|
||||||
*/
|
*/
|
||||||
@ -467,7 +449,7 @@ public:
|
|||||||
throw FLANNException("Branching factor must be at least 2");
|
throw FLANNException("Branching factor must be at least 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
free_elements();
|
free_indices();
|
||||||
|
|
||||||
for (int i=0; i<trees_; ++i) {
|
for (int i=0; i<trees_; ++i) {
|
||||||
indices[i] = new int[size_];
|
indices[i] = new int[size_];
|
||||||
@ -503,13 +485,12 @@ public:
|
|||||||
|
|
||||||
void loadIndex(FILE* stream) CV_OVERRIDE
|
void loadIndex(FILE* stream) CV_OVERRIDE
|
||||||
{
|
{
|
||||||
free_elements();
|
|
||||||
|
|
||||||
if (root!=NULL) {
|
if (root!=NULL) {
|
||||||
delete[] root;
|
delete[] root;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indices!=NULL) {
|
if (indices!=NULL) {
|
||||||
|
free_indices();
|
||||||
delete[] indices;
|
delete[] indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,6 +630,20 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the inner elements of indices[]
|
||||||
|
*/
|
||||||
|
void free_indices()
|
||||||
|
{
|
||||||
|
if (indices!=NULL) {
|
||||||
|
for(int i=0; i<trees_; ++i) {
|
||||||
|
if (indices[i]!=NULL) {
|
||||||
|
delete[] indices[i];
|
||||||
|
indices[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void computeLabels(int* dsindices, int indices_length, int* centers, int centers_length, int* labels, DistanceType& cost)
|
void computeLabels(int* dsindices, int indices_length, int* centers, int centers_length, int* labels, DistanceType& cost)
|
||||||
|
Loading…
Reference in New Issue
Block a user