/usr/include/OTB-5.8/otbDisparityMapEstimationMethod.txx is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | /*=========================================================================
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 otbDisparityMapEstimationMethod_txx
#define otbDisparityMapEstimationMethod_txx
#include "otbDisparityMapEstimationMethod.h"
#include "itkImageRegistrationMethod.h"
#include "otbExtractROI.h"
#include "otbMacro.h"
// #include "otbImageFileWriter.h"
//
namespace otb
{
/*
* Constructor.
*/
template <typename TFixedImage, typename TMovingImage, class TPointSet>
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::DisparityMapEstimationMethod()
{
this->SetNumberOfRequiredInputs(3);
//this->SetNumberOfRequiredOutputs(1);
// this->SetReleaseDataFlag(false);
this->SetReleaseDataBeforeUpdateFlag(false);
m_Transform = ITK_NULLPTR; // has to be provided by the user.
m_Interpolator = ITK_NULLPTR; // has to be provided by the user.
m_Metric = ITK_NULLPTR; // has to be provided by the user.
m_Optimizer = ITK_NULLPTR; // has to be provided by the user.
m_WinSize.Fill(15);
m_ExploSize.Fill(10);
m_InitialTransformParameters = ParametersType(1);
m_InitialTransformParameters.Fill(0.0f);
}
/*
* Destructor.
*/
template <class TFixedImage, class TMovingImage, class TPointSet>
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::~DisparityMapEstimationMethod()
{}
/**
* Set the source pointset.
* \param pointset The source pointset.
*/
template <class TFixedImage, class TMovingImage, class TPointSet>
void
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::SetPointSet(const TPointSet * pointset)
{
this->itk::ProcessObject::SetNthInput(0, const_cast<PointSetType *>(pointset));
}
/**
* Get the source pointset.
* \return The source pointset.
*/
template <class TFixedImage, class TMovingImage, class TPointSet>
const TPointSet *
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::GetPointSet(void)
{
return static_cast<const PointSetType *>(this->itk::ProcessObject::GetInput(0));
}
/**
* Set the fixed image.
* \param image The fixed image.
**/
template <class TFixedImage, class TMovingImage, class TPointSet>
void
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::SetFixedImage(const TFixedImage * image)
{
this->itk::ProcessObject::SetNthInput(1, const_cast<FixedImageType *>(image));
}
/**
* Get the fixed image.
* \return The fixed image.
**/
template <class TFixedImage, class TMovingImage, class TPointSet>
const TFixedImage *
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::GetFixedImage(void)
{
return static_cast<const FixedImageType *>(this->itk::ProcessObject::GetInput(1));
}
/**
* Set the moving image.
* \param image The mobing image.
**/
template <class TFixedImage, class TMovingImage, class TPointSet>
void
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::SetMovingImage(const TMovingImage * image)
{
this->itk::ProcessObject::SetNthInput(2, const_cast<MovingImageType *>(image));
}
/**
* Get the fixed image.
* \return The fixed image.
**/
template <class TFixedImage, class TMovingImage, class TPointSet>
const TMovingImage *
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::GetMovingImage(void)
{
return static_cast<const MovingImageType *>(this->itk::ProcessObject::GetInput(2));
}
/**
* Main computation method.
*/
template <class TFixedImage, class TMovingImage, class TPointSet>
void
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::GenerateData(void)
{
// inputs pointers
const FixedImageType * fixed = this->GetFixedImage();
const MovingImageType * moving = this->GetMovingImage();
const PointSetType * pointSet = this->GetPointSet();
PointSetType* output = this->GetOutput();
// Typedefs
typedef typename PointSetType::PointsContainer PointsContainer;
typedef typename PointsContainer::ConstIterator PointsIterator;
typedef itk::ImageRegistrationMethod<FixedImageType, MovingImageType> RegistrationType;
typedef otb::ExtractROI<FixedPixelType, FixedPixelType> FixedExtractType;
typedef otb::ExtractROI<MovingPixelType, MovingPixelType> MovingExtractType;
// points retrieving
typename PointsContainer::ConstPointer points = pointSet->GetPoints();
// Iterator set up
PointsIterator pointIterator = points->Begin();
PointsIterator end = points->End();
unsigned int dataId = 0;
otbMsgDevMacro(<< "Starting registration");
/// Iterate through the point set
while (pointIterator != end)
{
typename PointSetType::PointType p = pointIterator.Value(); // access the point
// Extract the needed sub-images
typename FixedExtractType::Pointer fixedExtractor = FixedExtractType::New();
typename MovingExtractType::Pointer movingExtractor = MovingExtractType::New();
fixedExtractor->SetInput(fixed);
movingExtractor->SetInput(moving);
// Fixed extractor setup
fixedExtractor->SetStartX(static_cast<unsigned long>(p[0] - m_ExploSize[0]));
fixedExtractor->SetStartY(static_cast<unsigned long>(p[1] - m_ExploSize[1]));
fixedExtractor->SetSizeX(static_cast<unsigned long>(2 * m_ExploSize[0] + 1));
fixedExtractor->SetSizeY(static_cast<unsigned long>(2 * m_ExploSize[1] + 1));
otbMsgDevMacro(<< "Point id: " << dataId);
otbMsgDevMacro(
<< "Fixed region: origin(" << p[0] - m_ExploSize[0] << ", " << p[1] - m_ExploSize[1] << ") size(" << 2 *
m_ExploSize[0] + 1 << ", " << 2 * m_ExploSize[1] + 1 << ")");
// Moving extractor setup
movingExtractor->SetStartX(static_cast<unsigned long>(p[0] - m_WinSize[0]));
movingExtractor->SetStartY(static_cast<unsigned long>(p[1] - m_WinSize[1]));
movingExtractor->SetSizeX(static_cast<unsigned long>(2 * m_WinSize[0] + 1));
movingExtractor->SetSizeY(static_cast<unsigned long>(2 * m_WinSize[1] + 1));
otbMsgDevMacro(
<< "Moving region: origin(" << p[0] - m_WinSize[0] << ", " << p[1] - m_WinSize[1] << ") size(" << 2 *
m_WinSize[0] + 1 << ", " << 2 * m_WinSize[1] + 1 << ")");
// update the extractors
fixedExtractor->Update();
movingExtractor->Update();
// std::cout<<"Fixed extract origin: "<<fixedExtractor->GetOutput()->GetOrigin()<<std::endl;
// std::cout<<"Fixed extract spacing: "<<fixedExtractor->GetOutput()->GetSpacing()<<std::endl;
// std::cout<<"Moving extract origin: "<<movingExtractor->GetOutput()->GetOrigin()<<std::endl;
// std::cout<<"Moving extract spacing: "<<movingExtractor->GetOutput()->GetSpacing()<<std::endl;
// typedef otb::ImageFileWriter<FixedImageType> FixedWriterType;
// typedef otb::ImageFileWriter<MovingImageType> MovingWriterType;
// typename FixedWriterType::Pointer fwriter = FixedWriterType::New();
// typename MovingWriterType::Pointer mwriter = MovingWriterType::New();
// std::ostringstream oss;
// oss.str("");
// oss<<"Fixed"<<dataId<<".tif";
// fwriter->SetInput(fixedExtractor->GetOutput());
// fwriter->SetFileName(oss.str());
// fwriter->Update();
// oss.str("");
// oss<<"Moving"<<dataId<<".tif";
// mwriter->SetInput(movingExtractor->GetOutput());
// mwriter->SetFileName(oss.str());
// mwriter->Update();
// Registration filter definition
typename RegistrationType::Pointer registration = RegistrationType::New();
// Registration filter setup
registration->SetOptimizer(m_Optimizer);
registration->SetTransform(m_Transform);
registration->SetInterpolator(m_Interpolator);
registration->SetMetric(m_Metric);
registration->SetFixedImage(fixedExtractor->GetOutput());
registration->SetMovingImage(movingExtractor->GetOutput());
// initial transform parameters setup
registration->SetInitialTransformParameters(m_InitialTransformParameters);
m_Interpolator->SetInputImage(movingExtractor->GetOutput());
// Perform the registration
registration->Update();
// Retrieve the final parameters
ParametersType finalParameters = registration->GetLastTransformParameters();
double value = m_Optimizer->GetValue(registration->GetLastTransformParameters());
// Computing moving image point
typename FixedImageType::PointType inputPoint, outputPoint;
typename FixedImageType::IndexType inputIndex;
// ensure that we have the right coord rep type
inputIndex[0] = static_cast<unsigned int>(p[0]);
inputIndex[1] = static_cast<unsigned int>(p[1]);
fixed->TransformIndexToPhysicalPoint(inputIndex, inputPoint);
m_Transform->SetParameters(finalParameters);
outputPoint = m_Transform->TransformPoint(inputPoint);
otbMsgDevMacro(<< "Metric value: " << value);
otbMsgDevMacro(<< "Transform parameters: " << finalParameters);
otbMsgDevMacro(
<< "Displacement: (" << outputPoint[0] - inputPoint[0] << ", " << outputPoint[1] - inputPoint[1] << ")");
otbMsgDevMacro(<< "Final parameters: " << finalParameters);
ParametersType data(finalParameters.GetSize() + 3);
data[0] = value;
data[1] = outputPoint[0] - inputPoint[0];
data[2] = outputPoint[1] - inputPoint[1];
for (unsigned int i = 0; i < finalParameters.GetSize(); ++i)
{
data[i + 3] = finalParameters[i];
}
// Set the parameters value in the point set data container.
output->SetPoint(dataId, p);
output->SetPointData(dataId, data);
// otbMsgDevMacro(<<"Point "<<dataId<<": "<<finalParameters);
++pointIterator; // advance to next point
++dataId;
}
}
template <class TFixedImage, class TMovingImage, class TPointSet>
void
DisparityMapEstimationMethod<TFixedImage, TMovingImage, TPointSet>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Window size: " << m_WinSize << std::endl;
os << indent << "Exploration size: " << m_ExploSize << std::endl;
}
}
#endif
|