21 #ifndef otbVectorDataToRightAngleVectorDataFilter_hxx
22 #define otbVectorDataToRightAngleVectorDataFilter_hxx
29 template <
class TVectorData>
32 this->SetNumberOfRequiredInputs(1);
33 this->SetNumberOfRequiredOutputs(1);
35 m_DistanceThreshold = 20.;
39 template <
class TVectorData>
43 typename VectorDataType::Pointer vData =
const_cast<VectorDataType*
>(this->GetInput());
46 this->GetOutput(0)->SetMetaDataDictionary(vData->GetMetaDataDictionary());
49 typename DataNodeType::Pointer root = this->GetOutput(0)->GetDataTree()->GetRoot()->Get();
51 typename DataNodeType::Pointer document = DataNodeType::New();
54 this->GetOutput(0)->GetDataTree()->Add(document, root);
56 typename DataNodeType::Pointer folder = DataNodeType::New();
58 this->GetOutput(0)->GetDataTree()->Add(folder, document);
59 this->GetOutput(0)->SetProjectionRef(vData->GetProjectionRef());
63 itVectorRef.GoToBegin();
65 while (!itVectorRef.IsAtEnd())
67 if (!itVectorRef.Get()->IsLineFeature())
74 while (!itVectorCur.IsAtEnd())
76 if (!itVectorCur.Get()->IsLineFeature())
82 double Angle = this->ComputeAngleFormedBySegments(itVectorRef.Get()->GetLine(), itVectorCur.Get()->GetLine());
85 if (std::abs(Angle -
CONST_PI_2) <= m_AngleThreshold)
89 RightAngleCoordinate = this->ComputeRightAngleCoordinate(itVectorRef.Get()->GetLine(), itVectorCur.Get()->GetLine());
92 double dist1_2 = this->ComputeDistanceFromPointToSegment(RightAngleCoordinate, itVectorRef.Get()->GetLine());
93 double dist2_2 = this->ComputeDistanceFromPointToSegment(RightAngleCoordinate, itVectorCur.Get()->GetLine());
95 double threshold_2 = m_DistanceThreshold * m_DistanceThreshold;
96 if (dist1_2 < threshold_2 && dist2_2 < threshold_2)
99 typename DataNodeType::Pointer CurrentGeometry = DataNodeType::New();
100 CurrentGeometry->SetNodeId(
"FEATURE_POINT");
102 CurrentGeometry->SetPoint(RightAngleCoordinate);
103 this->GetOutput(0)->GetDataTree()->Add(CurrentGeometry, folder);
113 template <
class TVectorData>
122 double l2 = v0.SquaredEuclideanDistanceTo(v1);
126 double u = ((rAngle[0] - v0[0]) * (v1[0] - v0[0]) + (rAngle[1] - v0[1]) * (v1[1] - v0[1])) / l2;
133 double x = v0[0] + u * (v1[0] - v0[0]);
134 double y = v0[1] + u * (v1[1] - v0[1]);
136 double dx = x - rAngle[0];
137 double dy = y - rAngle[1];
139 return dx * dx + dy * dy;
142 template <
class TVectorData>
145 double oriDst = this->ComputeOrientation(lineDst);
146 double oriSrc = this->ComputeOrientation(lineSrc);
148 return std::abs(oriDst - oriSrc);
151 template <
class TVectorData>
156 double Xp1 = vertexList->GetElement(0)[0];
157 double Yp1 = vertexList->GetElement(0)[1];
159 double Xp2 = vertexList->GetElement(1)[0];
160 double Yp2 = vertexList->GetElement(1)[1];
163 double dx = Xp1 - Xp2;
164 double dy = Yp1 - Yp2;
165 double orientation = std::atan2(dy, dx);
172 template <
class TVectorData>
179 double Xp1 = vertexListSrc->GetElement(0)[0];
180 double Yp1 = vertexListSrc->GetElement(0)[1];
181 double Xp2 = vertexListSrc->GetElement(1)[0];
182 double Yp2 = vertexListSrc->GetElement(1)[1];
185 double Xq1 = vertexListDst->GetElement(0)[0];
186 double Yq1 = vertexListDst->GetElement(0)[1];
187 double Xq2 = vertexListDst->GetElement(1)[0];
188 double Yq2 = vertexListDst->GetElement(1)[1];
190 double numU = (Xq2 - Xq1) * (Yp1 - Yq1) - (Yq2 - Yq1) * (Xp1 - Xq1);
191 double denumU = (Yq2 - Yq1) * (Xp2 - Xp1) - (Xq2 - Xq1) * (Yp2 - Yp1);
193 double u = numU / denumU;
195 P[0] = Xp1 + u * (Xp2 - Xp1);
196 P[1] = Yp1 + u * (Yp2 - Yp1);
201 template <
class TVectorData>
204 Superclass::PrintSelf(os, indent);