Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
d0174d49
Commit
d0174d49
authored
Nov 04, 2008
by
Emmanuel Christophe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Adding method to retrieve length for path and perimeter for polygons
parent
e301e251
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
207 additions
and
56 deletions
+207
-56
Code/Common/otbPolyLineParametricPathWithValue.h
Code/Common/otbPolyLineParametricPathWithValue.h
+17
-13
Code/Common/otbPolyLineParametricPathWithValue.txx
Code/Common/otbPolyLineParametricPathWithValue.txx
+87
-0
Code/Common/otbPolygon.h
Code/Common/otbPolygon.h
+7
-1
Code/Common/otbPolygon.txx
Code/Common/otbPolygon.txx
+50
-0
Testing/Code/Common/otbPolygon.cxx
Testing/Code/Common/otbPolygon.cxx
+46
-42
No files found.
Code/Common/otbPolyLineParametricPathWithValue.h
View file @
d0174d49
...
...
@@ -79,27 +79,31 @@ class ITK_EXPORT PolyLineParametricPathWithValue
}
return
resp
;
}
/**
* Return the path length (perimeter).
* \return The length.
*/
virtual
double
GetLength
();
protected:
/** Constructor */
PolyLineParametricPathWithValue
()
{
itk
::
MetaDataDictionary
&
dict
=
this
->
GetMetaDataDictionary
();
m_Key
=
"Value"
;
itk
::
EncapsulateMetaData
<
ValueType
>
(
dict
,
m_Key
,
0
);
};
PolyLineParametricPathWithValue
();
/** Destructor */
virtual
~
PolyLineParametricPathWithValue
()
{
}
/**PrintSelf method */
virtual
void
PrintSelf
(
std
::
ostream
&
os
,
itk
::
Indent
indent
)
const
{
Superclass
::
PrintSelf
(
os
,
indent
);
}
virtual
void
PrintSelf
(
std
::
ostream
&
os
,
itk
::
Indent
indent
)
const
;
private:
PolyLineParametricPathWithValue
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
std
::
string
m_Key
;
PolyLineParametricPathWithValue
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
std
::
string
m_Key
;
};
}
// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPolyLineParametricPathWithValue.txx"
#endif
#endif
Code/Common/otbPolyLineParametricPathWithValue.txx
0 → 100644
View file @
d0174d49
/*=========================================================================
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 __otbPolyLineParametricPathWithValue_txx
#define __otbPolyLineParametricPathWithValue_txx
#include "otbPolyLineParametricPathWithValue.h"
namespace otb
{
/**
* Constructor
*/
template < class TValue,unsigned int VDimension>
PolyLineParametricPathWithValue<TValue,VDimension>
::PolyLineParametricPathWithValue()
{
itk::MetaDataDictionary & dict = this->GetMetaDataDictionary();
m_Key = "Value";
itk::EncapsulateMetaData<ValueType>(dict,m_Key,0);
}
template < class TValue,unsigned int VDimension>
double PolyLineParametricPathWithValue<TValue,VDimension>
::GetLength()
{
double length = 0.0;
VertexListConstIteratorType it = this->GetVertexList()->Begin();
if(this->GetVertexList()->Size()>1)
{
VertexType pt1 = it.Value();//just init, won't be used like that
VertexType pt2 = it.Value();
it++;
while(it != this->GetVertexList()->End())
{
pt1=pt2;
pt2 = it.Value();
double accum=0.0;
for (int i=0; i<VDimension; i++)
{
accum += (pt1[i]-pt2[i])*(pt1[i]-pt2[i]);
}
length += vcl_sqrt(accum);
it++;
}
}
else //if there is strictly less than 2 points, length is 0
{
length = 0.0;
}
return length;
}
/**
* PrintSelf Method
*/
template < class TValue,unsigned int VDimension>
void
PolyLineParametricPathWithValue<TValue,VDimension>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // end namespace otb
#endif
\ No newline at end of file
Code/Common/otbPolygon.h
View file @
d0174d49
...
...
@@ -127,7 +127,13 @@ class ITK_EXPORT Polygon
* \return The surface.
*/
double
GetSurface
();
/**
* Return the polygon length (perimeter).
* \return The length.
*/
virtual
double
GetLength
();
protected:
/** Constructor */
Polygon
()
...
...
Code/Common/otbPolygon.txx
View file @
d0174d49
...
...
@@ -517,6 +517,56 @@ template<class TValue>
return m_Surface;
}
/**
* Lenght computation (difference with path is in the last addition)
*/
template < class TValue>
double Polygon<TValue>
::GetLength()
{
double length = 0.0;
VertexListConstIteratorType it = this->GetVertexList()->Begin();
VertexType origin = it.Value();
if(this->GetVertexList()->Size()>1)
{
VertexType pt1 = it.Value();//just init, won't be used like that
VertexType pt2 = it.Value();
it++;
while(it != this->GetVertexList()->End())
{
pt1=pt2;
pt2 = it.Value();
double accum=0.0;
for (int i=0; i<2; i++)
{
accum += (pt1[i]-pt2[i])*(pt1[i]-pt2[i]);
}
length += vcl_sqrt(accum);
it++;
}
//Adding the last segment (between first and last point)
double accum=0.0;
for (int i=0; i<2; i++)
{
accum += (origin[i]-pt2[i])*(origin[i]-pt2[i]);
}
length += vcl_sqrt(accum);
}
else //if there is strictly less than 2 points, length is 0
{
length = 0.0;
}
return length;
}
/**
* PrintSelf Method
*/
...
...
Testing/Code/Common/otbPolygon.cxx
View file @
d0174d49
...
...
@@ -39,25 +39,25 @@ int otbPolygon(int argc, char * argv[])
int
cpt
=
2
;
bool
first
=
true
;
while
(
argv
[
cpt
]
!=
NULL
&&
argv
[
cpt
+
1
]
!=
NULL
)
{
if
(
argv
[
cpt
][
0
]
==
'n'
)
{
if
(
argv
[
cpt
][
0
]
==
'n'
)
{
first
=
false
;
++
cpt
;
}
first
=
false
;
++
cpt
;
}
else
{
ContinuousIndexType
newVertex
;
newVertex
[
0
]
=
atof
(
argv
[
cpt
]);
newVertex
[
1
]
=
atof
(
argv
[
cpt
+
1
]);
if
(
first
)
polygon1
->
AddVertex
(
newVertex
);
else
{
ContinuousIndexType
newVertex
;
newVertex
[
0
]
=
atof
(
argv
[
cpt
]);
newVertex
[
1
]
=
atof
(
argv
[
cpt
+
1
]);
if
(
first
)
polygon1
->
AddVertex
(
newVertex
);
else
polygon2
->
AddVertex
(
newVertex
);
++
cpt
;
++
cpt
;
}
polygon2
->
AddVertex
(
newVertex
);
++
cpt
;
++
cpt
;
}
}
IteratorType
begin1
=
polygon1
->
GetVertexList
()
->
Begin
();
...
...
@@ -71,33 +71,33 @@ int otbPolygon(int argc, char * argv[])
file
.
open
(
outfile
);
for
(
it
=
begin1
;
it
!=
end1
;
++
it
)
{
file
<<
"polygon1->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
}
{
file
<<
"polygon1->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
}
file
<<
std
::
endl
<<
std
::
endl
;
for
(
it
=
begin2
;
it
!=
end2
;
++
it
)
{
file
<<
"polygon1->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
}
{
file
<<
"polygon1->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsInside("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsInside
(
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->IsOnEdge("
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
IsOnEdge
(
it
.
Value
())
<<
std
::
endl
;
}
file
<<
std
::
endl
<<
std
::
endl
;
current
=
begin1
.
Value
();
firstVertex
=
current
;
++
begin1
;
for
(
it
=
begin1
;
it
!=
end1
;
++
it
)
{
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
current
=
it
.
Value
();
}
{
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
current
=
it
.
Value
();
}
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
firstVertex
)
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
firstVertex
)
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
firstVertex
)
<<
std
::
endl
;
...
...
@@ -109,13 +109,13 @@ int otbPolygon(int argc, char * argv[])
firstVertex
=
current
;
++
begin2
;
for
(
it
=
begin2
;
it
!=
end2
;
++
it
)
{
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
current
=
it
.
Value
();
}
{
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
it
.
Value
())
<<
std
::
endl
;
file
<<
"polygon2->NbTouching("
<<
current
<<
", "
<<
it
.
Value
()
<<
") = "
<<
polygon2
->
NbTouching
(
current
,
it
.
Value
())
<<
std
::
endl
;
current
=
it
.
Value
();
}
file
<<
"polygon1->NbCrossing("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon1
->
NbCrossing
(
current
,
firstVertex
)
<<
std
::
endl
;
file
<<
"polygon1->NbTouching("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon1
->
NbTouching
(
current
,
firstVertex
)
<<
std
::
endl
;
file
<<
"polygon2->NbCrossing("
<<
current
<<
", "
<<
firstVertex
<<
") = "
<<
polygon2
->
NbCrossing
(
current
,
firstVertex
)
<<
std
::
endl
;
...
...
@@ -135,6 +135,10 @@ int otbPolygon(int argc, char * argv[])
file
<<
"Surface 1 :"
<<
(
double
)
polygon1
->
GetSurface
()
<<
std
::
endl
;
file
<<
"Surface 2 :"
<<
polygon2
->
GetSurface
()
<<
std
::
endl
;
file
<<
std
::
endl
<<
std
::
endl
;
file
<<
"Length computation : "
<<
std
::
endl
;
file
<<
"Length 1 :"
<<
(
double
)
polygon1
->
GetLength
()
<<
std
::
endl
;
file
<<
"Length 2 :"
<<
polygon2
->
GetLength
()
<<
std
::
endl
;
file
.
close
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment