This file is indexed.

/usr/include/OTB-5.8/otbPolygonToPolygonRCC8Calculator.txx is in libotb-dev 5.8.0+dfsg-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef otbPolygonToPolygonRCC8Calculator_txx
#define otbPolygonToPolygonRCC8Calculator_txx

#include "otbPolygonToPolygonRCC8Calculator.h"
#include "otbMacro.h"

namespace otb
{
/**
 * Constructor
 */
template<class TInputPolygon>
PolygonToPolygonRCC8Calculator<TInputPolygon>
::PolygonToPolygonRCC8Calculator()
{
  m_Value        = OTB_RCC8_DC;
  m_Level1APrioriKnowledge = false;
  m_Level3APrioriKnowledge = false;
}
/**
 * Get the RCC8 relation.
 * \return The RCC8 relation value.
 */
template <class TInputPolygon>
typename PolygonToPolygonRCC8Calculator<TInputPolygon>
::RCC8ValueType
PolygonToPolygonRCC8Calculator<TInputPolygon>
::GetValue(void)
{
  return m_Value;
}

template<class TInputPolygon>
void
PolygonToPolygonRCC8Calculator<TInputPolygon>
::Compute(void)
{
  // First check if bounding regions are disjoints
  RegionType region1 = m_Polygon1->GetBoundingRegion().GetImageRegion();
  RegionType region2 = m_Polygon2->GetBoundingRegion().GetImageRegion();

  // If intersection is not null, we have to do the computation
  if (!RegionsIntersectionIsNull(region1, region2))
    {

    bool edgeEdgeBool, interExterBool, exterInterBool, interInterBool;
    /// The boolean edgeEdge is needed in each case, so it si computed
    /// now
    edgeEdgeBool = ComputeEdgeEdge(m_Polygon1, m_Polygon2);

    //std::cout<<"EdgeEdge: "<<edgeEdgeBool<<std::endl;

    if (this->GetLevel1APrioriKnowledge())
      {
      interExterBool = true;
      }
    else
      {
      /// Else it must be computed
      interExterBool = ComputeInterExter(m_Polygon1, m_Polygon2);
      }

    //std::cout<<"InterExter: "<<interExterBool<<std::endl;

    /// At this stage we can determine if the relation is of type NTPP
    if ((!interExterBool) && (!edgeEdgeBool))
      {
      m_Value = OTB_RCC8_NTPP;
      }
    else
      {
      /// If not, we must consider the intersection between exterior
      if (this->GetLevel3APrioriKnowledge())
        {
        /// If the Level3APRioriKnowledge flag is set, this boolean
        /// can be determined from the two others
        exterInterBool = true;
        }
      else
        {
        /// Else it must be computed
        exterInterBool = ComputeInterExter(m_Polygon2, m_Polygon1);
        }

      //std::cout<<"ExterInter: "<<exterInterBool<<std::endl;

      /// If it is not sufficient to compute the relation
      if (!ComputeRelation(edgeEdgeBool, interExterBool, exterInterBool))
        {
        /// Compute the last boolean
        interInterBool = ComputeInterInter(m_Polygon1, m_Polygon2);

        //std::cout<<"InterInter: "<<interInterBool<<std::endl;

        /// Which allow the full determination
        if ((interExterBool) && (edgeEdgeBool) && (exterInterBool) && (!interInterBool))
          {
          m_Value = OTB_RCC8_EC;
          }
        else
          {
          m_Value = OTB_RCC8_PO;
          }
        }
      }
    }
}

template<class TInputPolygon>
bool
PolygonToPolygonRCC8Calculator<TInputPolygon>
::RegionsIntersectionIsNull(const RegionType& region1, const RegionType& region2)
{
  for (unsigned int dim = 0; dim < RegionType::ImageDimension; ++dim)
    {
    if (region1.GetIndex()[dim] + static_cast<int>(region1.GetSize()[dim]) < region2.GetIndex()[dim])
      {
      return true;
      }
    else if (region2.GetIndex()[dim] + static_cast<int>(region2.GetSize()[dim]) < region1.GetIndex()[dim])
      {
      return true;
      }
    }
  return false;
}

template<class TInputPolygon>
bool
PolygonToPolygonRCC8Calculator<TInputPolygon>
::ComputeRelation(bool edgeEdgeBool, bool interExterBool, bool exterInterBool)
{
  // This decision process is based on a decision tree
  if ((!interExterBool) && (edgeEdgeBool) && (!exterInterBool))
    {
    m_Value = OTB_RCC8_EQ;
    return true;
    }
  else if ((!interExterBool) && (edgeEdgeBool) && (exterInterBool))
    {
    m_Value = OTB_RCC8_TPP;
    return true;
    }
  else if ((interExterBool) && (!edgeEdgeBool) && (!exterInterBool))
    {
    m_Value = OTB_RCC8_NTPPI;
    return true;
    }
  else if ((interExterBool) && (!edgeEdgeBool) && (exterInterBool))
    {
    m_Value = OTB_RCC8_DC;
    return true;
    }
  else if ((interExterBool) && (edgeEdgeBool) && (!exterInterBool))
    {
    m_Value = OTB_RCC8_TPPI;
    return true;
    }
  else
    {
    return false;
    }
}

template<class TInputPolygon>
bool
PolygonToPolygonRCC8Calculator<TInputPolygon>
::ComputeInterExter(PolygonPointerType polygon1, PolygonPointerType polygon2)
{
  bool                        resp = false;
  VertexListConstIteratorType it = polygon1->GetVertexList()->Begin();
  VertexListConstIteratorType it_end = polygon1->GetVertexList()->End();

  ContinuousIndexType current = it.Value();
  ContinuousIndexType first = current;
  bool                isInside = polygon2->IsInside(current);
  bool                firstIsInside = isInside;
  bool                isExterior = !isInside && !polygon2->IsOnEdge(current);

  //std::cout<<current<<" is inside: "<<isInside<<std::endl;
  //std::cout<<current<<" is on edge: "<<polygon2->IsOnEdge(current)<<std::endl;

  unsigned int index = 0;
  if (isExterior)
    {
    resp = true;
    }
  ++it;
  while (!resp && it != it_end)
    {
    bool nextIsInside = polygon2->IsInside(it.Value());

    if (isInside && nextIsInside)
      {
      //std::cout<<current<<" is inside and "<<it.Value()<<" is inside, nb crossings: "<<polygon2->NbCrossing(current, it.Value())<<std::endl;
      resp = polygon2->NbCrossing(current, it.Value()) > 0;
      }
    current = it.Value();
    isInside  = nextIsInside;
    isExterior = !isInside && !polygon2->IsOnEdge(current);
    //std::cout<<current<<" is inside: "<<isInside<<std::endl;
    //std::cout<<current<<" is on edge: "<<polygon2->IsOnEdge(current)<<std::endl;
    if (isExterior)
      {
      resp = true;
      }

    ++index;
    ++it;
    }

  if (!resp && isInside && firstIsInside)
    {
    resp = polygon2->NbCrossing(current, first) > 0;
    //std::cout<<current<<" is inside and "<<first<<" is inside, nb crossings: "<<polygon2->NbCrossing(current, first)<<std::endl;
    }

  return resp;
}

template<class TInputPolygon>
bool
PolygonToPolygonRCC8Calculator<TInputPolygon>
::ComputeInterInter(PolygonPointerType polygon1, PolygonPointerType polygon2)
{
  bool                        resp = false;
  VertexListConstIteratorType it = polygon1->GetVertexList()->Begin();
  VertexListConstIteratorType it_end = polygon1->GetVertexList()->End();
  ContinuousIndexType         current = it.Value();
  ContinuousIndexType         first = current;
  bool                        currentIsInside = polygon2->IsInside(current);
  bool                        firstIsInside = currentIsInside;

  if (currentIsInside)
    {
    resp = true;
    }
  ++it;
  while (!resp && it != it_end)
    {
    bool nextIsInside = polygon2->IsInside(it.Value());

    if (!currentIsInside && !nextIsInside && !polygon2->IsOnEdge(current) && !polygon2->IsOnEdge(it.Value()))
      {
      unsigned int nbCrossings = polygon2->NbCrossing(current, it.Value());

      resp = nbCrossings > 0;
      }
    currentIsInside = nextIsInside;
    current = it.Value();

    if (currentIsInside)
      {
      resp = true;
      }
    ++it;
    }

  if (!resp && !currentIsInside && !firstIsInside && !polygon2->IsOnEdge(current) && !polygon2->IsOnEdge(first))
    {
    unsigned int nbCrossings = polygon2->NbCrossing(current, first);

    resp = nbCrossings > 0;
    }
  return resp;
}
template<class TInputPolygon>
bool
PolygonToPolygonRCC8Calculator<TInputPolygon>
::ComputeEdgeEdge(PolygonPointerType polygon1, PolygonPointerType polygon2)
{
  bool                        resp = false;
  VertexListConstIteratorType it = polygon1->GetVertexList()->Begin();
  VertexListConstIteratorType it_end = polygon1->GetVertexList()->End();

  ContinuousIndexType current = it.Value();
  resp = polygon2->IsOnEdge(current);
  //std::cout<<"IsOnEdge: "<<current<<": "<<polygon2->IsOnEdge(current)<<std::endl;
  ContinuousIndexType first = current;
  ++it;

  while (!resp && it != it_end)
    {
    if (polygon2->NbTouching(current, it.Value()) > 0)
      {
      resp = true;
      //std::cout<<"NbCrossing: "<<current<<" -> "<<it.Value()<<": "<<polygon2->NbCrossing(current, it.Value())<<std::endl;
      }
    if (polygon2->NbCrossing(current, it.Value()) > 0)
      {
      resp = true;
      //std::cout<<"NbTouching: "<<current<<" -> "<<it.Value()<<": "<<polygon2->NbTouching(current, it.Value())<<std::endl;
      }
    current = it.Value();

    if (polygon2->IsOnEdge(current))
      {
      resp = true;
      //std::cout<<"IsOnEdge: "<<current<<": "<<polygon2->IsOnEdge(current)<<std::endl;
      }
    ++it;
    }
  if (!resp && polygon2->NbTouching(current, first) > 0)
    {
    resp = true;
    //std::cout<<"NbCrossing: "<<current<<" -> "<<first<<": "<<polygon2->NbCrossing(current, first)<<std::endl;
    }
  if (polygon2->NbCrossing(current, first) > 0)
    {
    resp = true;
    //std::cout<<"NbTouching: "<<current<<" -> "<<first<<": "<<polygon2->NbTouching(current, first)<<std::endl;
    }

  return resp;
}
/**
 * PrintSelf method
 */
template<class TInputPolygon>
void
PolygonToPolygonRCC8Calculator<TInputPolygon>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  Superclass::PrintSelf(os, indent);
}
} // end namespace otb

#endif