Commit 1f671be8 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

REFAC: remove SpatialObjects module

parent e60455a2
Pipeline #2028 passed with stages
in 54 minutes and 18 seconds
<PAMDataset>
<GeoTransform> -1.0050000000000000e+02, 1.0000000000000000e+00, 0.0000000000000000e+00, -5.0500000000000000e+01, 0.0000000000000000e+00, 1.0000000000000000e+00</GeoTransform>
</PAMDataset>
#
# 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.
#
project(OTBSpatialObjects)
otb_module_impl()
/*
* 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 otbDrawLineSpatialObjectFilter_h
#define otbDrawLineSpatialObjectFilter_h
#include "itkSpatialObjectToImageFilter.h"
#include "otbDrawLineSpatialObjectListFilter.h"
//#include <list>
namespace otb
{
/** \class DrawLineSpatialObjectFilter
* \brief Application of a filter which draw line in a binary image.
*
* This class implements a filter that draws line in a binary image.
* Inputs are a LineSpatialObject and an input image that is used to
* allocate the output image. This filter copies the input image in
* the output image.
*
*
* \ingroup OTBSpatialObjects
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT DrawLineSpatialObjectFilter :
//public itk::SpatialObjectToImageFilter< itk::LineSpatialObject<2>, TOutputImage >
public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Extract dimensions as well of the images of entry of exit. */
itkStaticConstMacro(InputImageDimension,
unsigned int,
TInputImage::ImageDimension);
itkStaticConstMacro(OutputImageDimension,
unsigned int,
TOutputImage::ImageDimension);
/** typedef for the classes standards. */
typedef DrawLineSpatialObjectFilter Self;
//typedef itk::ImageTo< itk::LineSpatialObject<2>, TOutputImage > Superclass;
typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for management of the "object factory". */
itkNewMacro(Self);
/** Return the name of the class. */
itkTypeMacro(DrawLineSpatialObjectFilter, /*SpatialObjectToImageFilter*/ itk::ImageToImageFilter);
/** typedef Support for input & output image*/
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::PixelType OutputPixelType;
/** Support typedef for input & Output*/
typedef itk::LineSpatialObject<2> InputLineType;
typedef itk::ProcessObject ProcessObjectType;
/** Typedef Support for lineList Type*/
typedef LineSpatialObjectList LineSpatialObjectListType;
typedef typename LineSpatialObjectListType::Pointer LineSpatialObjectListPointer;
/** Typedef Support for drawLineSpatialObjectListFilter*/
typedef otb::DrawLineSpatialObjectListFilter<InputImageType, OutputImageType> DrawLineSpatialObjectListFilterType;
typedef typename DrawLineSpatialObjectListFilterType::Pointer
DrawLineSpatialObjectListFilterPointerType;
/** Set/Get the image input of this process object. */
/* virtual void SetInputImage(const InputImageType *image); */
/* const InputImageType * GetInputImage(void); */
/** Get the input LineSpatialObjet (not const) */
virtual void SetInputLine(const InputLineType *line);
InputLineType * GetInputLine(void);
/** Set/Get pixel value */
itkSetMacro(Value, OutputPixelType);
itkGetConstReferenceMacro(Value, OutputPixelType);
protected:
DrawLineSpatialObjectFilter();
~DrawLineSpatialObjectFilter() override {}
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
void GenerateData() override;
private:
DrawLineSpatialObjectFilter(const Self &) = delete;
void operator =(const Self&) = delete;
OutputPixelType m_Value;
DrawLineSpatialObjectListFilterPointerType m_DrawLineListFilter;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbDrawLineSpatialObjectFilter.hxx"
#endif
#endif
/*
* 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 otbDrawLineSpatialObjectFilter_hxx
#define otbDrawLineSpatialObjectFilter_hxx
#include "otbDrawLineSpatialObjectFilter.h"
#include "itkDataObject.h"
#include "itkMacro.h"
#include "itkImageRegionIterator.h"
#include "itkImageIteratorWithIndex.h"
namespace otb
{
/**
*
*/
template <class TInputImage, class TOutputImage>
DrawLineSpatialObjectFilter<TInputImage, TOutputImage>::DrawLineSpatialObjectFilter()
{
this->SetNumberOfRequiredInputs(2);
this->SetNumberOfRequiredOutputs(1);
m_Value = static_cast<OutputPixelType>(255.0);
m_DrawLineListFilter = DrawLineSpatialObjectListFilterType::New();
}
template <class TInputImage, class TOutputImage>
void
DrawLineSpatialObjectFilter<TInputImage, TOutputImage>
::SetInputLine(const InputLineType *line)
{
this->ProcessObjectType::SetNthInput(1,
const_cast<InputLineType *>(line));
}
template <class TInputImage, class TOutputImage>
typename DrawLineSpatialObjectFilter<TInputImage, TOutputImage>::InputLineType *
DrawLineSpatialObjectFilter<TInputImage, TOutputImage>
::GetInputLine(void)
{
return static_cast<InputLineType *>
(this->ProcessObjectType::GetInput(1));
}
template <class TInputImage, class TOutputImage>
void
DrawLineSpatialObjectFilter<TInputImage, TOutputImage>
::GenerateData(void)
{
typename InputImageType::ConstPointer input = this->GetInput();
InputLineType * line = this->GetInputLine();
typename OutputImageType::Pointer output = this->GetOutput();
/** Create a new list line with one line*/
LineSpatialObjectListPointer lineList = LineSpatialObjectListType::New();
lineList->push_back(line);
/** Invoke the DrawLineSpatialObjectListFilter to draw the line */
m_DrawLineListFilter->SetInput(input);
m_DrawLineListFilter->SetInputLineSpatialObjectList(lineList);
m_DrawLineListFilter->GraftOutput(this->GetOutput());
m_DrawLineListFilter->Update();
this->GraftOutput(m_DrawLineListFilter->GetOutput());
}
/**
* Standard "PrintSelf" method
*/
template <class TInputImage, class TOutput>
void
DrawLineSpatialObjectFilter<TInputImage, TOutput>::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Path Value: " << m_Value << std::endl;
}
} // end namespace otb
#endif
/*
* 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 otbDrawLineSpatialObjectListFilter_h
#define otbDrawLineSpatialObjectListFilter_h
#include "itkImageToImageFilter.h"
#include "otbLineSpatialObjectList.h"
namespace otb
{
/** \class DrawLineSpatialObjectListFilter
* \brief Composite filter which draw lines in an image.
*
* This class implements a composite filter that draws a list of lines in
* an input Image. This class
*
*
*
*
* \ingroup OTBSpatialObjects
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT DrawLineSpatialObjectListFilter :
public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Extract dimensions as well of the images of entry of exit. */
itkStaticConstMacro(InputImageDimension,
unsigned int,
TInputImage::ImageDimension);
itkStaticConstMacro(OutputImageDimension,
unsigned int,
TOutputImage::ImageDimension);
/** typedefs support for inputs & outputs*/
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
/** typedef for the classes standards. */
typedef DrawLineSpatialObjectListFilter Self;
typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef LineSpatialObjectList LinesListType;
typedef LinesListType::LineType LineType;
typedef LineType::PointListType PointListType;
typedef typename LinesListType::const_iterator LineListIterator;
typedef itk::ProcessObject ProcessObjectType;
/** Method for management of the "object factory". */
itkNewMacro(Self);
/** Return the name of the class. */
itkTypeMacro(DrawLineSpatialObjectListFilter, ImageToImageFilter);
/** Definition of the input and output images */
typedef typename InputImageType::PixelType InputPixelType;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::IndexType OutputIndexType;
typedef typename OutputIndexType::IndexValueType OutputIndexValueType;
/** Set/Get the image input of this process object. */
virtual void SetInputLineSpatialObjectList(const LinesListType * list);
LinesListType * GetInputLineSpatialObjectList(void);
/** Get/Set m_Value*/
itkGetMacro(Value, OutputPixelType);
itkSetMacro(Value, OutputPixelType);
protected:
DrawLineSpatialObjectListFilter();
~DrawLineSpatialObjectListFilter() override {}
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
/**
* compute the intersection of the segment to draw with the region
*/
virtual void CropSegment(OutputIndexType *indexToCrop,
OutputIndexType *otherIndex,
const OutputImageRegionType *outputRegionForThread) const;
virtual void CropRightSegment(OutputIndexType *indexToCrop,
OutputIndexType *otherIndex,
const OutputImageRegionType *outputRegionForThread) const;
virtual bool IsUpsideTheRegion(OutputIndexType *indexToCrop,
const OutputImageRegionType *outputRegionForThread) const;
virtual bool IsDownsideTheRegion(OutputIndexType *indexToCrop,
const OutputImageRegionType *outputRegionForThread) const;
virtual bool IsDownsideTheImage(OutputIndexType *indexToCrop) const;
virtual bool IsColumnOutsideOfTheRegion(OutputIndexType *indexToCheck,
OutputIndexType *otherToCheck,
const OutputImageRegionType *outputRegionForThread) const;
private:
DrawLineSpatialObjectListFilter(const Self &) = delete;
void operator =(const Self&) = delete;
OutputPixelType m_Value;
int m_Length;
int m_Width;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbDrawLineSpatialObjectListFilter.hxx"
#endif
#endif
/*
* 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 otbDrawLineSpatialObjectListFilter_hxx
#define otbDrawLineSpatialObjectListFilter_hxx
#include "otbDrawLineSpatialObjectListFilter.h"
#include "itkLineIterator.h"
#include "itkDataObject.h"
#include "itkImageRegionIterator.h"
namespace otb
{
/**
*
*/
template <class TInputImage, class TOutputImage>
DrawLineSpatialObjectListFilter<TInputImage, TOutputImage>
::DrawLineSpatialObjectListFilter()
{
this->SetNumberOfRequiredInputs(2);
this->SetNumberOfRequiredOutputs(1);
m_Value = static_cast<OutputPixelType>(255.);
}
template <class TInputImage, class TOutputImage>
void
DrawLineSpatialObjectListFilter<TInputImage, TOutputImage>
::SetInputLineSpatialObjectList(const LinesListType * list)
{
this->ProcessObjectType::SetNthInput(1,
const_cast<LinesListType *>(list));
}
template <class TInputImage, class TOutputImage>
typename DrawLineSpatialObjectListFilter<TInputImage, TOutputImage>::LinesListType *
DrawLineSpatialObjectListFilter<TInputImage, TOutputImage>
::GetInputLineSpatialObjectList(void)
{
//ROMAIN
return static_cast</*const*/ LinesListType*>
(this->ProcessObjectType::GetInput(1));
}
template <class TInputImage, class TOutputImage>
void
DrawLineSpatialObjectListFilter<TInputImage, TOutputImage>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType itkNotUsed(threadId))
{
typename InputImageType::ConstPointer input = this->GetInput();
typename OutputImageType::Pointer output = this->GetOutput();
typename LinesListType::Pointer list = const_cast<LinesListType*>(this->GetInputLineSpatialObjectList());
/** Copy the input requested region in the output requested region*/
typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
OutputIteratorType outputIt(output, outputRegionForThread);
InputIteratorType inputIt(input, outputRegionForThread);
outputIt.GoToBegin();
inputIt.GoToBegin();
for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt, ++inputIt)
outputIt.Set(static_cast<OutputPixelType>(inputIt.Get()));
/** Draw the lines in the output image using lineIterator*/
typedef itk::LineIterator<OutputImageType> LineIteratorFilter;
OutputIndexType indexBeginLine, indexEndLine;
LineListIterator itList = list->begin();
typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
m_Length = size[1];
m_Width = size[0];
while (itList != list->end())
{
PointListType& pointsList = (*itList)->GetPoints();
typename PointListType::const_iterator itPoints = pointsList.begin();
indexBeginLine[0] = static_cast<OutputIndexValueType>((*itPoints).GetPosition()[0]);
indexBeginLine[1] = static_cast<OutputIndexValueType>((*itPoints).GetPosition()[1]);
++itPoints; //Get the second extremity of the segment
indexEndLine[0] = static_cast<OutputIndexValueType>((*itPoints).GetPosition()[0]);
indexEndLine[1] = static_cast<OutputIndexValueType>((*itPoints).GetPosition()[1]);
/** Crop the segment if it is outside the region in the left*/
if (!(this->IsColumnOutsideOfTheRegion(&indexBeginLine, &indexEndLine,
&outputRegionForThread) &&
this->IsColumnOutsideOfTheRegion(&indexEndLine, &indexBeginLine, &outputRegionForThread)))
{
if (indexEndLine[0] >= static_cast<OutputIndexValueType>(size[0]))
this->CropRightSegment(&indexEndLine,
&indexBeginLine,
&outputRegionForThread);
if (indexBeginLine[0] >= static_cast<OutputIndexValueType>(size[0]))
this->CropRightSegment(
&indexBeginLine,
&indexEndLine,
&
outputRegionForThread);
}
/**
* If an extremity is under the region
* Technically, the X component of the index is inside the image
*/
if (this->IsDownsideTheImage(&indexBeginLine) &&
input->GetLargestPossibleRegion().IsInside(indexEndLine))
this->CropSegment(&indexBeginLine,
&indexEndLine,
&outputRegionForThread);
if (this->IsDownsideTheImage(&indexEndLine) &&
input->GetLargestPossibleRegion().IsInside(indexBeginLine))
this->CropSegment(&indexEndLine,
&indexBeginLine,
&outputRegionForThread);
/** If the segments are not in the region (upside or downside the region)*/
if (!(this->IsUpsideTheRegion(&indexBeginLine,
&outputRegionForThread) &&
this->IsUpsideTheRegion(&indexEndLine, &outputRegionForThread)) &&
!(this->IsDownsideTheRegion(&indexBeginLine,
&outputRegionForThread) &&
this->IsDownsideTheRegion(&indexEndLine, &outputRegionForThread)) &&
!(this->IsColumnOutsideOfTheRegion(&indexBeginLine, &indexEndLine,
&outputRegionForThread) &&
this->IsColumnOutsideOfTheRegion(&indexEndLine, &indexBeginLine, &outputRegionForThread))
)
{
/** Instantiation of the line iterator with begin and ending index*/
LineIteratorFilter itLine(output, indexBeginLine, indexEndLine);
/** Iteration over the line and writing white lines */
while (!itLine.IsAtEnd())
{
if (outputRegionForThread.IsInside(itLine.GetIndex())) itLine.Set(m_Value);
++itLine;
}
}
++itList;
}
}
/**
* Compute the intersection between the segment to draw and the region belonging to the current thread
* It is used if the segment abcisse is greater than the width of the image
*
*/
template <class TInputImage, class TOutput>
void
DrawLineSpatialObjectListFilter<TInputImage, TOutput>
::CropRightSegment(OutputIndexType *indexToCrop,
OutputIndexType *otherIndex,
const OutputImageRegionType *outputRegionForThread) const