Commit 315ba059 authored by Cédric Traizet's avatar Cédric Traizet

REFAC: remove LineSpatialObjectListToRightAnglePointSetFilter

parent 4facfd77
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbLineSpatialObjectListToRightAnglePointSetFilter_h
#define otbLineSpatialObjectListToRightAnglePointSetFilter_h
#include "itkPointSet.h"
#include "otbLineSpatialObjectListToPointSetFilter.h"
#include "otbMath.h"
#include "itkVariableSizeMatrix.h"
namespace otb
{
/** \class LineSpatialObjectListToRightAnglePointSetFilter
* \brief TODO
*
* \ingroup OTBCorner
*/
template <class TImage, class TLinesList, class TPointSet>
class ITK_EXPORT LineSpatialObjectListToRightAnglePointSetFilter
: public otb::LineSpatialObjectListToPointSetFilter <TLinesList, TPointSet>
{
public:
/** Standard class typedefs. */
typedef LineSpatialObjectListToRightAnglePointSetFilter Self;
typedef LineSpatialObjectListToPointSetFilter <TLinesList, TPointSet> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(LineSpatialObjectListToRightAnglePointSetFilter, LineSpatialObjectListToPointSetFilter);
/** Typedef support for ProcessObject*/
typedef itk::ProcessObject ProcessObjectType;
/** Template parameters typedefs*/
typedef TLinesList InputLinesListType;
typedef typename InputLinesListType::LineType LineType;
typedef std::vector<LineType*> VectorLineType;
//typedef typename LineType::PointListType InputPointListType;
typedef typename InputLinesListType::const_iterator InputLinesListTypeIterator;
/** Typdedef for The input image :
* (ONLY USED FOR THE LINE ITERATOR -> To check if the index is inside the region)
*/
typedef TImage InputImageType;
typedef typename InputImageType::IndexType InputIndexType;
/** Typedef support for output PointSet*/
typedef TPointSet OutputPointSetType;
typedef typename OutputPointSetType::PointType PointType;
typedef typename OutputPointSetType::Pointer OutputPointSetPointerType;
/** Typedef Support for Checking couple of segments used*/
typedef itk::VariableSizeMatrix<unsigned int> checkMatrixType;
/**
* Public Methods :
* Get the Input Image & Get The input Image
*/
virtual InputImageType* GetInputImage();
virtual void SetInputImage(InputImageType *);
/** Set/Get the thresholds*/
itkGetMacro(ThresholdDistance, double);
itkSetMacro(ThresholdDistance, double);
itkGetMacro(ThresholdAngle, double);
itkSetMacro(ThresholdAngle, double);
protected:
/**
* Without the GenerateOutputInformation below it does not work
* Because the ProcessObject class do a static_cast to allow memory and copy
* the output (here a pointset). It works fine with images but with pointsets
* no size is specified ...
* the aim of the GenerateOutputInformation below is to avoid the guilty static_cast
*
*/
void GenerateOutputInformation() override{}
/**
* Constructor.
*/
LineSpatialObjectListToRightAnglePointSetFilter();
/**
* Destructor.
*/
~LineSpatialObjectListToRightAnglePointSetFilter() override{}
/**
* Standard PrintSelf method.
*/
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
/**
* Main computation method.
*/
void GenerateData() override;
/**
* Angle computation
*/
virtual double ComputeAngleFormedBySegments(LineType * lineDst, LineType * lineSrc);
/**
* When we find a right angle, one compute the coordinate of the segments intersection
*/
virtual PointType ComputeAngleRightCoordinate(LineType * lineDst, LineType * lineSrc);
/**
* AddRightAngleToPointSet
*/
virtual void AddRightAngleToPointSet(PointType rAngle, LineType * LineDst, LineType* LineCur);
/**
* Compute the orienation of a segment
*/
virtual double ComputeOrientation(LineType* line);
/**
* Distance From a point rAngle to a segment line
*/
virtual double ComputeDistanceFromPointToSegment(PointType rAngle, LineType * line);
private:
LineSpatialObjectListToRightAnglePointSetFilter(const Self &) = delete;
void operator =(const Self&) = delete;
/** Smart pointer on the output PointSet*/
OutputPointSetPointerType m_OutputPointSet;
double m_ThresholdDistance;
double m_ThresholdAngle;
};
}
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbLineSpatialObjectListToRightAnglePointSetFilter.hxx"
#endif
#endif
......@@ -22,9 +22,7 @@ otb_module_test()
set(OTBCornerTests
otbCornerTestDriver.cxx
otbLineSpatialObjectListToRightAnglePointSetFilter.cxx
otbVectorDataToRightAngleVectorDataFilter.cxx
otbLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii.cxx
otbHarrisImage.cxx
otbHarrisToPointSet.cxx
)
......@@ -35,15 +33,6 @@ otb_module_target_label(otbCornerTestDriver)
# Tests Declaration
otb_add_test(NAME feTvLineSpatialObjectListToRightAnglePointSetFilter COMMAND otbCornerTestDriver
--compare-ascii ${EPSILON_3}
${BASELINE_FILES}/feTvLineSpatialObjectListToRightAnglePointSetFilterOutputAscii.txt
${TEMP}/feTvLineSpatialObjectListToRightAnglePointSetFilterOutputAscii.txt
otbLineSpatialObjectListToRightAnglePointSetFilter
${INPUTDATA}/carre.png
${TEMP}/feTvLineSpatialObjectListToRightAnglePointSetFilterOutputAscii.txt
)
otb_add_test(NAME feTvVectorDataToRightAngleVectorDataFilter COMMAND otbCornerTestDriver
--compare-ogr ${EPSILON_8}
${BASELINE_FILES}/feTvVectorDataToRightAngleVectorDataFilterOutput.shp
......@@ -53,15 +42,6 @@ otb_add_test(NAME feTvVectorDataToRightAngleVectorDataFilter COMMAND otbCornerTe
${TEMP}/feTvVectorDataToRightAngleVectorDataFilterOutput.shp #output text file
)
otb_add_test(NAME feTvLineSpatialObjectListToRightAnglePointSetFilterBySteps COMMAND otbCornerTestDriver
--compare-ascii ${EPSILON_3}
${BASELINE_FILES}/feTvLineSpatialObjectListToRightAnglePointSetFilterOutputAscii.txt
${TEMP}/feTvLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii.txt
otbLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii
${INPUTDATA}/carre.png
${TEMP}/feTvLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii.txt
)
otb_add_test(NAME feTvHarrisImage COMMAND otbCornerTestDriver
--compare-image ${NOTOL} ${BASELINE}/feHarrisImage.png
${TEMP}/feHarrisImage.png
......
......@@ -22,9 +22,7 @@
void RegisterTests()
{
REGISTER_TEST(otbLineSpatialObjectListToRightAnglePointSetFilter);
REGISTER_TEST(otbVectorDataToRightAngleVectorDataFilter);
REGISTER_TEST(otbLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii);
REGISTER_TEST(otbHarrisImage);
REGISTER_TEST(otbHarrisToPointSet);
}
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbImage.h"
#include "otbLineSpatialObjectListToRightAnglePointSetFilter.h"
#include "otbLineSpatialObjectList.h"
#include "otbImageFileReader.h"
#include <iostream>
#include <fstream>
int otbLineSpatialObjectListToRightAnglePointSetFilter(int itkNotUsed(argc), char * argv[])
{
const char * infname = argv[1];
const char * outfname = argv[2];
const unsigned int Dimension = 2;
typedef float PixelType;
/** Typedefs */
typedef otb::Image<PixelType, Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::LineSpatialObjectList LinesListType;
typedef LinesListType::LineType LineType;
typedef std::vector<LineType*> VectorLines;
typedef itk::PointSet<VectorLines, Dimension> PointSetType;
typedef otb::LineSpatialObjectListToRightAnglePointSetFilter<ImageType, LinesListType,
PointSetType> RightAngleFilterType;
/** Creatop, of an instance of the filters */
RightAngleFilterType::Pointer rightAngleFilter = RightAngleFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
PointSetType::Pointer segmentOrtho = PointSetType::New();
/** Creation of lines */
LinesListType::Pointer list = LinesListType::New();
LineType::PointListType pointList;
LineType::LinePointType point;
// Definition of the first line
float Ux, Uy, Vx, Vy;
Ux = 31.7;
Uy = 11.1;
Vx = 31.7;
Vy = 25.1;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line = LineType::New();
line->SetId(0);
line->SetPoints(pointList);
line->ComputeBoundingBox();
list->push_back(line);
pointList.clear();
// Definition of a second line
Ux = 10.1;
Uy = 10.7;
Vx = 30.1;
Vy = 10.6;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line2 = LineType::New();
line2->SetId(0);
line2->SetPoints(pointList);
line2->ComputeBoundingBox();
list->push_back(line2);
pointList.clear();
// Definition of a third line
Ux = 20.1;
Uy = 7.1;
Vx = 40.5;
Vy = 17.1;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line3 = LineType::New();
line3->SetId(0);
line3->SetPoints(pointList);
line3->ComputeBoundingBox();
list->push_back(line3);
// Begin the process
reader->SetFileName(infname);
rightAngleFilter->SetInputImage(reader->GetOutput());
rightAngleFilter->SetInput(list);
rightAngleFilter->Update();
/** Writing The result in the outfile*/
std::ofstream outfile(outfname);
outfile << "Number of right angles detected " << rightAngleFilter->GetOutput()->GetNumberOfPoints() << std::endl;
/** Draw the orthogonal segments */
segmentOrtho = rightAngleFilter->GetOutput();
PointSetType::PointType pRight;
for (unsigned int i = 0; i < segmentOrtho->GetNumberOfPoints(); ++i)
{
segmentOrtho->GetPoint(i, &pRight);
outfile << " Right Angle found in point : " << pRight << std::endl;
}
outfile.close();
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbImage.h"
#include "otbLineSpatialObjectListToRightAnglePointSetFilter.h"
#include "otbDrawLineSpatialObjectListFilter.h"
#include "otbImageFileReader.h"
#include <iostream>
#include <fstream>
int otbLineSpatialObjectListToRightAnglePointSetFilterByStepsOutputAscii(int itkNotUsed(argc), char * argv[])
{
const char * infname = argv[1];
const char * outfname = argv[2];
const unsigned int Dimension = 2;
typedef float PixelType;
/** Typedefs */
typedef otb::Image<PixelType, Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::LineSpatialObjectList LinesListType;
typedef LinesListType::LineType LineType;
typedef std::vector<LineType*> VectorLines;
typedef itk::PointSet<VectorLines, Dimension> PointSetType;
typedef otb::LineSpatialObjectListToRightAnglePointSetFilter<ImageType, LinesListType,
PointSetType> RightAngleFilterType;
/** Creatop, of an instance of the filters */
RightAngleFilterType::Pointer rightAngleFilter = RightAngleFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
PointSetType::Pointer segmentOrtho = PointSetType::New();
/** Creation of lines */
LinesListType::Pointer list = LinesListType::New();
LineType::PointListType pointList;
LineType::LinePointType point;
// Definition of the first line
float Ux, Uy, Vx, Vy;
Ux = 31.7;
Uy = 11.1;
Vx = 31.7;
Vy = 25.1;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line = LineType::New();
line->SetId(0);
line->SetPoints(pointList);
line->ComputeBoundingBox();
list->push_back(line);
pointList.clear();
// Definition of a second line
Ux = 10.1;
Uy = 10.7;
Vx = 30.1;
Vy = 10.6;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line2 = LineType::New();
line2->SetId(0);
line2->SetPoints(pointList);
line2->ComputeBoundingBox();
list->push_back(line2);
pointList.clear();
// Definition of a third line
Ux = 20.1;
Uy = 7.1;
Vx = 40.5;
Vy = 17.1;
point.SetPosition(Ux, Uy);
pointList.push_back(point);
point.SetPosition(Vx, Vy);
pointList.push_back(point);
LineType::Pointer line3 = LineType::New();
line3->SetId(0);
line3->SetPoints(pointList);
line3->ComputeBoundingBox();
list->push_back(line3);
// Begin the process
reader->SetFileName(infname);
rightAngleFilter->SetInputImage(reader->GetOutput());
rightAngleFilter->SetInput(list);
rightAngleFilter->Update();
std::cout << "Number of right angles detected " << rightAngleFilter->GetOutput()->GetNumberOfPoints() << std::endl;
/** Print the right angles coordinate in the output file*/
segmentOrtho = rightAngleFilter->GetOutput();
PointSetType::PointType pRight;
VectorLines outputVectorLines;
LinesListType::Pointer outputLinesList = LinesListType::New();
std::ofstream outfile(outfname);
outfile << "Number of right angles detected " << rightAngleFilter->GetOutput()->GetNumberOfPoints() << std::endl;
for (unsigned int i = 0; i < segmentOrtho->GetNumberOfPoints(); ++i)
{
segmentOrtho->GetPoint(i, &pRight);
outfile << " Right Angle found in point : " << pRight << std::endl;
/** Example To extract The coordinate of the segment (Just for example)*/
segmentOrtho->GetPointData(i, &outputVectorLines);
outputLinesList->push_back(outputVectorLines[0]);
outputLinesList->push_back(outputVectorLines[1]);
}
outfile.close();
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment