@@ -89,36 +89,38 @@ void GCException::Report()
89
89
GCoptimization::GCoptimization (SiteID nSites, LabelID nLabels)
90
90
: m_num_labels(nLabels)
91
91
, m_num_sites(nSites)
92
+ , m_labeling(new LabelID[nSites])
93
+ , m_lookupSiteVar(new SiteID[nSites])
94
+ , m_labelTable(new LabelID[nLabels])
95
+ , m_stepsThisCycle(0 )
96
+ , m_stepsThisCycleTotal(0 )
97
+ , m_random_label_order(false )
92
98
, m_datacostIndividual(0 )
93
99
, m_smoothcostIndividual(0 )
100
+ , m_labelingDataCosts(new EnergyTermType[nSites])
101
+ , m_labelCounts(new SiteID[nLabels])
102
+ , m_activeLabelCounts(new SiteID[m_num_labels])
94
103
, m_labelcostsAll(0 )
95
104
, m_labelcostsByLabel(0 )
96
105
, m_labelcostCount(0 )
97
- , m_smoothcostFn(0 )
106
+ , m_labelingInfoDirty(true )
107
+ , m_verbosity(0 )
98
108
, m_datacostFn(0 )
109
+ , m_smoothcostFn(0 )
110
+ , m_beforeExpansionEnergy(0 )
111
+ , m_numNeighbors(0 )
99
112
, m_numNeighborsTotal(0 )
113
+ , m_giveSmoothEnergyInternal(0 )
100
114
, m_queryActiveSitesExpansion(&GCoptimization::queryActiveSitesExpansion<DataCostFnFromArray>)
101
- , m_setupDataCostsSwap(0 )
102
115
, m_setupDataCostsExpansion(0 )
103
- , m_setupSmoothCostsSwap(0 )
104
116
, m_setupSmoothCostsExpansion(0 )
117
+ , m_setupDataCostsSwap(0 )
118
+ , m_setupSmoothCostsSwap(0 )
105
119
, m_applyNewLabeling(0 )
106
120
, m_updateLabelingDataCosts(0 )
107
- , m_giveSmoothEnergyInternal(0 )
108
- , m_solveSpecialCases(&GCoptimization::solveSpecialCases<DataCostFnFromArray>)
109
121
, m_datacostFnDelete(0 )
110
122
, m_smoothcostFnDelete(0 )
111
- , m_random_label_order(false )
112
- , m_verbosity(0 )
113
- , m_labelingInfoDirty(true )
114
- , m_lookupSiteVar(new SiteID[nSites])
115
- , m_labeling(new LabelID[nSites])
116
- , m_labelTable(new LabelID[nLabels])
117
- , m_labelingDataCosts(new EnergyTermType[nSites])
118
- , m_labelCounts(new SiteID[nLabels])
119
- , m_activeLabelCounts(new SiteID[m_num_labels])
120
- , m_stepsThisCycle(0 )
121
- , m_stepsThisCycleTotal(0 )
123
+ , m_solveSpecialCases(&GCoptimization::solveSpecialCases<DataCostFnFromArray>)
122
124
{
123
125
if ( nLabels <= 1 ) handleError (" Number of labels must be >= 2" );
124
126
if ( nSites <= 0 ) handleError (" Number of sites must be >= 1" );
@@ -132,8 +134,8 @@ GCoptimization::GCoptimization(SiteID nSites, LabelID nLabels)
132
134
handleError (" Not enough memory." );
133
135
}
134
136
135
- memset (m_labeling, 0 , m_num_sites* sizeof (LabelID));
136
- memset (m_lookupSiteVar,-1 ,m_num_sites* sizeof (SiteID));
137
+ memset (m_labeling, 0 , ( size_t ) m_num_sites * sizeof (LabelID));
138
+ memset (m_lookupSiteVar,-1 , ( size_t ) m_num_sites * sizeof (SiteID));
137
139
setLabelOrder (false );
138
140
specializeSmoothCostFunctor (SmoothCostFnPotts ());
139
141
}
@@ -739,7 +741,7 @@ void GCoptimization::setDataCost(SiteID s, LabelID l, EnergyTermType e) {
739
741
if ( !m_datacostIndividual )
740
742
{
741
743
EnergyTermType* table = new EnergyTermType[m_num_sites*m_num_labels];
742
- memset (table, 0 , m_num_sites* m_num_labels* sizeof (EnergyTermType));
744
+ memset (table, 0 , ( size_t ) m_num_sites * ( size_t ) m_num_labels * sizeof (EnergyTermType));
743
745
specializeDataCostFunctor (DataCostFnFromArray (table, m_num_labels));
744
746
m_datacostIndividual = table;
745
747
m_labelingInfoDirty = true ;
@@ -807,7 +809,7 @@ void GCoptimization::setSmoothCost(LabelID l1, LabelID l2, EnergyTermType e){
807
809
if ( !m_smoothcostIndividual )
808
810
{
809
811
EnergyTermType* table = new EnergyTermType[m_num_labels*m_num_labels];
810
- memset (table, 0 , m_num_labels* m_num_labels* sizeof (EnergyTermType));
812
+ memset (table, 0 , ( size_t ) m_num_labels * ( size_t ) m_num_labels * sizeof (EnergyTermType));
811
813
specializeSmoothCostFunctor (SmoothCostFnFromArray (table, m_num_labels));
812
814
m_smoothcostIndividual = table;
813
815
}
@@ -864,13 +866,13 @@ void GCoptimization::setLabelSubsetCost(LabelID* labels, LabelID numLabels, Ener
864
866
865
867
if ( !m_labelcostsByLabel ) {
866
868
m_labelcostsByLabel = new LabelCostIter*[m_num_labels];
867
- memset (m_labelcostsByLabel, 0 , m_num_labels*sizeof (void *));
869
+ memset (m_labelcostsByLabel, 0 , ( size_t ) m_num_labels*sizeof (void *));
868
870
}
869
871
870
872
// If this particular subset already has a cost, simply replace it.
871
873
for ( LabelCostIter* lci = m_labelcostsByLabel[labels[0 ]]; lci; lci = lci->next ) {
872
874
if ( numLabels == lci->node ->numLabels ) {
873
- if ( !memcmp (labels, lci->node ->labels , numLabels* sizeof (LabelID)) ) {
875
+ if ( !memcmp (labels, lci->node ->labels , ( size_t ) numLabels * sizeof (LabelID)) ) {
874
876
// This label subset already exists, so just update the cost and return
875
877
lci->node ->cost = cost;
876
878
return ;
@@ -889,7 +891,7 @@ void GCoptimization::setLabelSubsetCost(LabelID* labels, LabelID numLabels, Ener
889
891
lc->aux = -1 ;
890
892
lc->numLabels = numLabels;
891
893
lc->labels = new LabelID[numLabels];
892
- memcpy (lc->labels , labels, numLabels* sizeof (LabelID));
894
+ memcpy (lc->labels , labels, ( size_t ) numLabels * sizeof (LabelID));
893
895
slist_prepend (m_labelcostsAll, lc);
894
896
for ( LabelID i = 0 ; i < numLabels; ++i ) {
895
897
LabelCostIter* lci = new LabelCostIter;
@@ -903,7 +905,7 @@ void GCoptimization::setLabelSubsetCost(LabelID* labels, LabelID numLabels, Ener
903
905
void GCoptimization::whatLabel (SiteID start, SiteID count, LabelID* labeling)
904
906
{
905
907
assert (start >= 0 && start+count <= m_num_sites);
906
- memcpy (labeling, m_labeling+start, count* sizeof (LabelID));
908
+ memcpy (labeling, m_labeling+start, ( size_t ) count * sizeof (LabelID));
907
909
}
908
910
909
911
// -------------------------------------------------------------------
@@ -1062,8 +1064,8 @@ void GCoptimization::setLabelOrder(const LabelID* order, LabelID size)
1062
1064
if ( order[i] < 0 || order[i] >= m_num_labels )
1063
1065
handleError (" Invalid label id in setLabelOrder" );
1064
1066
m_random_label_order = false ;
1065
- memcpy (m_labelTable,order,size* sizeof (LabelID));
1066
- memset (m_labelTable+size,-1 ,( m_num_labels-size)* sizeof (LabelID));
1067
+ memcpy (m_labelTable,order, ( size_t ) size * sizeof (LabelID));
1068
+ memset (m_labelTable+size,-1 , ( size_t ) ( m_num_labels-size) * sizeof (LabelID));
1067
1069
}
1068
1070
1069
1071
// ------------------------------------------------------------------
@@ -1103,7 +1105,7 @@ GCoptimization::EnergyType GCoptimization::setupLabelCostsExpansion(SiteID size,
1103
1105
{
1104
1106
// For sparse data costs, things are more complicated, because we must ensure that
1105
1107
// no label cost for a fixed (non-active) non-alpha label is encoded in the graph.
1106
- memset (m_activeLabelCounts,0 ,m_num_labels* sizeof (SiteID));
1108
+ memset (m_activeLabelCounts,0 , ( size_t ) m_num_labels * sizeof (SiteID));
1107
1109
for ( SiteID i = 0 ; i < size; ++i )
1108
1110
m_activeLabelCounts[m_labeling[activeSites[i]]]++;
1109
1111
@@ -1164,7 +1166,7 @@ void GCoptimization::updateLabelingInfo(bool updateCounts, bool updateActive, bo
1164
1166
{
1165
1167
if ( updateCounts )
1166
1168
{
1167
- memset (m_labelCounts,0 ,m_num_labels* sizeof (SiteID));
1169
+ memset (m_labelCounts,0 , ( size_t ) m_num_labels * sizeof (SiteID));
1168
1170
for ( SiteID i = 0 ; i < m_num_sites; ++i )
1169
1171
m_labelCounts[m_labeling[i]]++;
1170
1172
}
@@ -1173,8 +1175,7 @@ void GCoptimization::updateLabelingInfo(bool updateCounts, bool updateActive, bo
1173
1175
{
1174
1176
for ( LabelCost* lc = m_labelcostsAll; lc; lc = lc->next )
1175
1177
lc->active = false ;
1176
-
1177
- EnergyType energy = 0 ;
1178
+
1178
1179
for ( LabelID l = 0 ; l < m_num_labels; ++l )
1179
1180
if ( m_labelCounts[l] )
1180
1181
for ( LabelCostIter* lci = m_labelcostsByLabel[l]; lci; lci = lci->next )
@@ -1187,7 +1188,7 @@ void GCoptimization::updateLabelingInfo(bool updateCounts, bool updateActive, bo
1187
1188
if (m_updateLabelingDataCosts)
1188
1189
(this ->*m_updateLabelingDataCosts)();
1189
1190
else
1190
- memset (m_labelingDataCosts,0 ,m_num_sites* sizeof (EnergyTermType));
1191
+ memset (m_labelingDataCosts,0 , ( size_t ) m_num_sites * sizeof (EnergyTermType));
1191
1192
}
1192
1193
}
1193
1194
@@ -1776,14 +1777,14 @@ void GCoptimization::DataCostFnSparse::set(LabelID l, const SparseDataCost* cost
1776
1777
//
1777
1778
if (!m_buckets) {
1778
1779
m_buckets = new DataCostBucket[m_num_labels*m_buckets_per_label];
1779
- memset (m_buckets, 0 , m_num_labels* m_buckets_per_label* sizeof (DataCostBucket));
1780
+ memset (m_buckets, 0 , ( size_t ) m_num_labels * ( size_t ) m_buckets_per_label * sizeof (DataCostBucket));
1780
1781
}
1781
1782
1782
1783
DataCostBucket* b = &m_buckets[l*m_buckets_per_label];
1783
1784
if (b->begin )
1784
1785
delete [] b->begin ;
1785
1786
SparseDataCost* next = new SparseDataCost[count];
1786
- memcpy (next,costs,count* sizeof (SparseDataCost));
1787
+ memcpy (next,costs, ( size_t ) count * sizeof (SparseDataCost));
1787
1788
1788
1789
//
1789
1790
// Scan the list of costs and remember pointers to delimit the 'buckets', i.e. where
0 commit comments