Commit ea78cfb9b9f663fbd6797526d373d95145014992

Authored by raffaele.gaetano
1 parent c4115e48
Exists in master

FIX: Changed long unsigned int to std::size_t and long int to __int64 for 64bit …

…node ids under Windows.
include/grmGraph.h
... ... @@ -43,7 +43,7 @@ namespace grm
43 43 Node is identified by the location
44 44 of the first pixel of the region.
45 45 */
46   - long unsigned int m_Id;
  46 + std::size_t m_Id;
47 47  
48 48 /*
49 49 Bounding box of the region
... ... @@ -77,7 +77,6 @@ namespace grm
77 77 return ptr;
78 78 }
79 79 };
80   -
81 80  
82 81 template<class DerivedNode>
83 82 struct Node : BaseNode
... ...
include/grmGraphOperations.txx
... ... @@ -39,7 +39,7 @@ namespace grm
39 39 {
40 40 for(auto& r : seg.m_Graph.m_Nodes)
41 41 {
42   - long int neighborhood[4];
  42 + __int64 neighborhood[4];
43 43 FOURNeighborhood(neighborhood, r->m_Id, width, height);
44 44 for(short j = 0; j < 4; ++j)
45 45 {
... ... @@ -53,7 +53,7 @@ namespace grm
53 53 {
54 54 for(auto& r : seg.m_Graph.m_Nodes)
55 55 {
56   - long int neighborhood[8];
  56 + __int64 neighborhood[8];
57 57 EIGHTNeighborhood(neighborhood, r->m_Id, width, height);
58 58 bool haveNeighbors = false;
59 59 for(short j = 0; j < 8; ++j)
... ... @@ -79,7 +79,7 @@ namespace grm
79 79 void GraphOperations<TSegmenter>::UpdateMergingCosts(SegmenterType& seg)
80 80 {
81 81 float min_cost;
82   - long unsigned int min_id = 0;
  82 + std::size_t min_id = 0;
83 83 std::size_t idx, min_idx;
84 84  
85 85 for(auto& r : seg.m_Graph.m_Nodes)
... ... @@ -145,18 +145,21 @@ namespace grm
145 145 typename GraphOperations<TSegmenter>::NodePointerType
146 146 GraphOperations<TSegmenter>::CheckLMBF(NodePointerType a, float t)
147 147 {
148   - if(a->m_Valid)
  148 + // TO FIX: if no-data are present within the image, an edgeless node is possible
  149 + // Here we check if the list of edges is empty prior to cost check.
  150 + // if(a->m_Valid)
  151 + if(a->m_Valid && a->m_Edges.size() > 0)
149 152 {
150 153 float cost = a->m_Edges.front().m_Cost;
151 154  
152 155 if(cost < t)
153 156 {
154 157 NodePointerType b = a->m_Edges.front().GetRegion();
155   -
  158 +
156 159 if( b->m_Valid)
157 160 {
158 161 NodePointerType best_b = b->m_Edges.front().GetRegion();
159   -
  162 +
160 163 if(a == best_b)
161 164 {
162 165 if(a->m_Id < b->m_Id)
... ... @@ -174,7 +177,10 @@ namespace grm
174 177 typename GraphOperations<TSegmenter>::NodePointerType
175 178 GraphOperations<TSegmenter>::CheckBF(NodePointerType a, float t)
176 179 {
177   - if(a->m_Valid)
  180 + // TO FIX: if no-data are present within the image, an edgeless node is possible
  181 + // Here we check if the list of edges is empty prior to cost check.
  182 + // if(a->m_Valid)
  183 + if(a->m_Valid && a->m_Edges.size() > 0)
178 184 {
179 185 float cost = a->m_Edges.front().m_Cost;
180 186  
... ... @@ -318,7 +324,7 @@ namespace grm
318 324  
319 325 /* Update the costs of merging between adjacent nodes */
320 326 UpdateMergingCosts(seg);
321   -
  327 +
322 328 for(auto& region : seg.m_Graph.m_Nodes)
323 329 {
324 330  
... ... @@ -412,7 +418,7 @@ namespace grm
412 418 {
413 419 bool merged = false;
414 420  
415   - std::vector<long unsigned int> randomIndices(seg.m_Graph.m_Nodes.size());
  421 + std::vector<std::size_t> randomIndices(seg.m_Graph.m_Nodes.size());
416 422 std::iota(randomIndices.begin(), randomIndices.end(), 0);
417 423 std::shuffle(randomIndices.begin(), randomIndices.end(), std::mt19937{std::random_device{}()});
418 424  
... ...
include/grmNeighborhood.h
... ... @@ -18,17 +18,19 @@
18 18 #ifndef GRM_NEIGHBORHOOD_H
19 19 #define GRM_NEIGHBORHOOD_H
20 20  
  21 +#include <cstddef>
  22 +
21 23 enum CONNECTIVITY{FOUR = 0, EIGHT};
22 24  
23 25 namespace grm
24 26 {
25   - void FOURNeighborhood(long int * neighborhood,
26   - const long unsigned int id,
  27 + void FOURNeighborhood(__int64 * neighborhood,
  28 + const std::size_t id,
27 29 const unsigned int width,
28 30 const unsigned int height);
29 31  
30   - void EIGHTNeighborhood(long int * neighborhood,
31   - const long unsigned int id,
  32 + void EIGHTNeighborhood(__int64 * neighborhood,
  33 + const std::size_t id,
32 34 const unsigned int width,
33 35 const unsigned int height);
34 36 } // end of namespace grm
... ...
include/grmSegmenter.h
... ... @@ -129,7 +129,7 @@ namespace grm
129 129 this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
130 130 this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
131 131  
132   - const long unsigned int num_nodes = this->m_ImageWidth * this->m_ImageHeight;
  132 + const std::size_t num_nodes = this->m_ImageWidth * this->m_ImageHeight;
133 133 this->m_Graph.m_Nodes.reserve(num_nodes);
134 134  
135 135 std::vector<bool> noDataFlags;
... ... @@ -163,7 +163,6 @@ namespace grm
163 163  
164 164 this->m_Graph.m_Nodes.push_back(n);
165 165 ++idx;
166   -
167 166 }
168 167 }
169 168  
... ...
src/grmNeighborhood.cxx
... ... @@ -19,13 +19,13 @@
19 19  
20 20 namespace grm
21 21 {
22   - void FOURNeighborhood(long int * neighborhood,
23   - const long unsigned int id,
  22 + void FOURNeighborhood(__int64 * neighborhood,
  23 + const std::size_t id,
24 24 const unsigned int width,
25 25 const unsigned int height)
26 26 {
27   - const unsigned int x = id % width;
28   - const unsigned int y = id / width;
  27 + const std::size_t x = id % width;
  28 + const std::size_t y = id / width;
29 29  
30 30 /* top */
31 31 neighborhood[0] = ( y > 0 ? (id - width) : -1 );
... ... @@ -40,13 +40,13 @@ namespace grm
40 40 neighborhood[3] = ( x > 0 ? (id - 1) : -1 );
41 41 }
42 42  
43   - void EIGHTNeighborhood(long int * neighborhood,
44   - const long unsigned int id,
  43 + void EIGHTNeighborhood(__int64 * neighborhood,
  44 + const std::size_t id,
45 45 const unsigned int width,
46 46 const unsigned int height)
47 47 {
48   - const unsigned int x = id % width;
49   - const unsigned int y = id / width;
  48 + const std::size_t x = id % width;
  49 + const std::size_t y = id / width;
50 50  
51 51 /* top */
52 52 neighborhood[0] = ( y > 0 ? (id - width) : -1 );
... ...