21 #ifndef otbRectangle_hxx
22 #define otbRectangle_hxx
35 template <
class TValue>
39 if (m_VertexList->Size() < 2)
40 itkGenericExceptionMacro(<<
"Rectangle needs TWO vertex, up-to-date the start and the end of the segments with AdDVertex Method ");
49 double lengthSeg = std::sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]));
53 middleP[0] = (p1[0] + p2[0]) / 2.;
54 middleP[1] = (p1[1] + p2[1]) / 2.;
58 corner[0] = middleP[0] + (m_Width / 2) * std::sin(m_Orientation);
59 corner[1] = middleP[1] - (m_Width / 2) * std::cos(m_Orientation);
62 if (this->ComputeEuclideanDistanceMetricToSegment(p1, p2, point) - (m_Width / 2.) < 1e-10 &&
63 this->ComputeEuclideanDistanceMetricToSegment(middleP, corner, point) - (lengthSeg / 2.) < 1e-10)
73 template <
class TValue>
83 double SegmentLength = std::sqrt((Xq1 - Xq2) * (Xq1 - Xq2) + (Yq1 - Yq2) * (Yq1 - Yq2));
84 double CrossProduct = Xq1 * Yq2 - Xq2 * Yq1;
85 double Num = std::abs(xp * (Yq1 - Yq2) + yp * (Xq2 - Xq1) + CrossProduct);
88 return (Num / SegmentLength);
95 template <
class TValue>
105 double dx = std::cos(m_Orientation);
106 double dy = std::sin(m_Orientation);
107 double halfWidth = m_Width / 2;
113 tempCorner[0] = p1[0] + dy * halfWidth;
114 tempCorner[1] = p1[1] - dx * halfWidth;
115 cornersVertex->InsertElement(cornersVertex->Size(), tempCorner);
117 tempCorner[0] = p1[0] - dy * halfWidth;
118 tempCorner[1] = p1[1] + dx * halfWidth;
119 cornersVertex->InsertElement(cornersVertex->Size(), tempCorner);
121 tempCorner[0] = p2[0] + dy * halfWidth;
122 tempCorner[1] = p2[1] - dx * halfWidth;
123 cornersVertex->InsertElement(cornersVertex->Size(), tempCorner);
125 tempCorner[0] = p2[0] - dy * halfWidth;
126 tempCorner[1] = p2[1] + dx * halfWidth;
127 cornersVertex->InsertElement(cornersVertex->Size(), tempCorner);
131 typename RegionType::SizeType size;
132 typename RegionType::IndexType index;
133 typename RegionType::IndexType maxId;
141 long int x = 0, y = 0;
143 if (cornersVertex->Size() > 0)
145 x =
static_cast<long int>(itCorners.Value()[0]);
146 y =
static_cast<long int>(itCorners.Value()[1]);
151 while (itCorners != cornersVertex->End())
153 x =
static_cast<long int>(itCorners.Value()[0]);
154 y =
static_cast<long int>(itCorners.Value()[1]);
178 size[0] = maxId[0] - index[0];
179 size[1] = maxId[1] - index[1];
181 region.SetSize(size);
182 region.SetIndex(index);
190 template <
class TValue>
193 if (m_VertexList->Size() > 1)
194 itkGenericExceptionMacro(<<
"Rectangle needs only TWO vertex, a width and an orientation ");
196 m_VertexList->InsertElement(m_VertexList->Size(), vertex);
202 template <
class TValue>
205 os << indent <<
"Vertices: " << m_VertexList << std::endl;