KSquare Utilities
ImageFeaturesDataIndexed.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdio.h>
3 #include <ctype.h>
4 #include <time.h>
5 #include <string>
6 #include <limits>
7 #include <iostream>
8 #include <fstream>
9 #include <vector>
10 #include "MemoryDebug.h"
11 using namespace std;
12 
13 
14 #include "KKBaseTypes.h"
15 using namespace KKB;
16 
17 
19 #include "FeatureVector.h"
20 using namespace KKMLL;
21 
22 
23 
25 
26 
28 
29 
30 
33 {
34 }
35 
36 
37 
40 {
41  FeatureVectorPtr example = NULL;
42  for (auto idx: examples)
43  {
44  example = idx;
45  RBInsert (example);
46  }
47 }
48 
49 
50 
51 
52 
53 void ImageFeaturesDataIndexed::RBInsert (FeatureVectorPtr example)
54 {
55  RBTree<ImageDataTreeEntry, ExtractFeatureData, ImageFeaturesNodeKey>::RBInsert (new ImageDataTreeEntry (example));
56 }
57 
58 
59 
60 
61 
62 FeatureVectorPtr ImageFeaturesDataIndexed::GetEqual (const FeatureVectorPtr example)
63 {
64  ImageDataTreeEntryPtr entry = new ImageDataTreeEntry (example);
65 
66  ImageDataTreeEntryPtr newEntry = RBTree<ImageDataTreeEntry, ExtractFeatureData, ImageFeaturesNodeKey>::GetEqual (entry->NodeKey ());
67 
68  FeatureVectorPtr exampleFound = NULL;
69  if (newEntry)
70  exampleFound = newEntry->Example ();
71 
72  delete entry; entry = NULL;
73 
74  return exampleFound;
75 }
76 
77 
78 
79 
80 
81 ImageDataTreeEntry::ImageDataTreeEntry (FeatureVectorPtr _example):
82  example (_example),
83  nodeKey (_example)
84 
85 {
86 }
87 
88 
89 
90 ImageFeaturesNodeKey::ImageFeaturesNodeKey (FeatureVectorPtr _example):
91  example (_example)
92 {
93 }
94 
95 
96 
97 
98 bool ImageFeaturesNodeKey::operator== (const ImageFeaturesNodeKey& rightNode) const
99 {
100  return (CompareTwoExamples (example, rightNode.example) == 0);
101 }
102 
103 bool ImageFeaturesNodeKey::operator< (const ImageFeaturesNodeKey& rightNode) const
104 {
105  return (CompareTwoExamples (example, rightNode.example) < 0);
106 }
107 
108 bool ImageFeaturesNodeKey::operator> (const ImageFeaturesNodeKey& rightNode) const
109 {
110  return (CompareTwoExamples (example, rightNode.example) > 0);
111 }
112 
113 
114 
115 kkint32 ImageFeaturesNodeKey::CompareTwoExamples (const FeatureVectorPtr i1,
116  const FeatureVectorPtr i2
117  ) const
118 {
119  const float* f1 = i1->FeatureDataConst ();
120  const float* f2 = i2->FeatureDataConst ();
121 
122  for (kkint32 x = 0; x < i1->NumOfFeatures (); x++)
123  {
124  if (f1[x] < f2[x])
125  return -1;
126  else if (f1[x] > f2[x])
127  return 1;
128  }
129 
130  return 0;
131 } /* CompareTwoImageFeaturesObjects */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
ImageFeaturesDataIndexed(const FeatureVectorList &examples)
void RBInsert(FeatureVectorPtr example)
Container class for FeatureVector derived objects.
KKTHread * KKTHreadPtr
const float * FeatureDataConst() const
ImageFeaturesNodeKey(FeatureVectorPtr _example)
ExtractFeatureData extractFeatureData
ImageDataTreeEntry(FeatureVectorPtr _example)
bool operator>(const ImageFeaturesNodeKey &rightNode) const
FeatureVectorPtr Example()
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
bool operator==(const ImageFeaturesNodeKey &rightNode) const
kkint32 CompareTwoExamples(const FeatureVectorPtr i1, const FeatureVectorPtr i2) const
ImageDataTreeEntry * ImageDataTreeEntryPtr
bool operator<(const ImageFeaturesNodeKey &rightNode) const