/usr/include/OTB-6.4/otbGenericRSTransform.txx is in libotb-dev 6.4.0+dfsg-1.
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | /*
* Copyright (C) 2005-2017 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 otbGenericRSTransform_txx
#define otbGenericRSTransform_txx
#include "otbGenericRSTransform.h"
#include "otbMacro.h"
#include "otbMetaDataKey.h"
#include "itkMetaDataObject.h"
#include "otbGeoInformationConversion.h"
#include "ogr_spatialref.h"
namespace otb
{
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::GenericRSTransform() : Superclass(0)
{
m_InputProjectionRef.clear();
m_OutputProjectionRef.clear();
m_InputKeywordList.Clear();
m_OutputKeywordList.Clear();
m_InputSpacing.Fill(1);
m_InputOrigin.Fill(0);
m_OutputSpacing.Fill(1);
m_OutputOrigin.Fill(0);
m_Transform = ITK_NULLPTR;
m_InputTransform = ITK_NULLPTR;
m_OutputTransform = ITK_NULLPTR;
m_TransformUpToDate = false;
m_TransformAccuracy = Projection::UNKNOWN;
}
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
const typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::TransformType*
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::GetTransform() const
{
itkDebugMacro("returning MapProjection address " << this->m_Transform);
if ((!m_TransformUpToDate) || (m_Transform.IsNull()))
{
itkExceptionMacro(<< "m_Transform not up-to-date, call InstantiateTransform() first");
}
return this->m_Transform;
}
/**
* Instantiate the transformation according to information
*/
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
void
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::InstantiateTransform(void)
{
m_Transform = TransformType::New();
if (m_InputKeywordList.GetSize() == 0)
{
itk::ExposeMetaData<ImageKeywordlist>(m_InputDictionary, MetaDataKey::OSSIMKeywordlistKey, m_InputKeywordList);
}
if (m_InputProjectionRef.empty())
{
itk::ExposeMetaData<std::string>(m_InputDictionary, MetaDataKey::ProjectionRefKey, m_InputProjectionRef);
}
otbMsgDevMacro(<< "Information to instantiate transform: ");
otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
otbMsgDevMacro(<< " * Input keyword list: "
<< ((m_InputKeywordList.GetSize() == 0) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Input projection: " << m_InputProjectionRef);
otbMsgDevMacro(<< " * Output keyword list: "
<< ((m_OutputKeywordList.GetSize() == 0) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Output projection: " << m_OutputProjectionRef);
otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
//Make sure that the state is clean:
m_InputTransform = ITK_NULLPTR;
m_OutputTransform = ITK_NULLPTR;
bool firstTransformGiveGeo = true;
bool inputTransformIsSensor = false;
bool inputTransformIsMap = false;
bool outputTransformIsSensor = false;
bool outputTransformIsMap = false;
// Prepare the projection ref (eventually convert the EPSG code into full WKT)
//
// Note that we do that at the GenericRSTransform level and not in the member
// class for several reasons:
// - at the GenericMapProjection and MapProjectionAdapter the method are
// called SetWkt and thus should not take a SRID.
// - we do not want to mix the GeoInformationConversion (which uses gdal) in
// the MapProjectionAdapter to keep ossim and gdal dependencies as separated
// as possible.
m_InputProjectionRef = GeoInformationConversion::ToWKT(m_InputProjectionRef);
m_OutputProjectionRef = GeoInformationConversion::ToWKT(m_OutputProjectionRef);
//*****************************
//Set the input transformation
//*****************************
// First, try to make a geo transform
if (!m_InputProjectionRef.empty()) //map projection
{
typedef otb::GenericMapProjection<TransformDirection::INVERSE, ScalarType, InputSpaceDimension, InputSpaceDimension>
InverseMapProjectionType;
typename InverseMapProjectionType::Pointer mapTransform = InverseMapProjectionType::New();
mapTransform->SetWkt(m_InputProjectionRef);
if (mapTransform->IsProjectionDefined())
{
m_InputTransform = mapTransform.GetPointer();
inputTransformIsMap = true;
otbMsgDevMacro(<< "Input projection set to map transform: " << m_InputTransform);
}
}
// If not, try to make a sensor model
if ((m_InputTransform.IsNull()) && (m_InputKeywordList.GetSize() > 0))
{
typedef otb::ForwardSensorModel<double, InputSpaceDimension, InputSpaceDimension> ForwardSensorModelType;
typename ForwardSensorModelType::Pointer sensorModel = ForwardSensorModelType::New();
sensorModel->SetImageGeometry(m_InputKeywordList);
if (sensorModel->IsValidSensorModel())
{
m_InputTransform = sensorModel.GetPointer();
inputTransformIsSensor = true;
otbMsgDevMacro(<< "Input projection set to sensor model.");
}
}
if (m_InputTransform.IsNull()) //default if we didn't manage to instantiate it before
{
m_InputTransform = itk::IdentityTransform<double, NInputDimensions>::New();
// firstTransformGiveGeo = false;
OGRSpatialReferenceH hSRS = ITK_NULLPTR;
hSRS = OSRNewSpatialReference(ITK_NULLPTR);
const char * wktString = m_InputProjectionRef.c_str();
if (OSRImportFromWkt(hSRS, (char **) &wktString) != OGRERR_NONE)
{
firstTransformGiveGeo = false;
otbMsgDevMacro(<< "- Considering that the first transform does not give geo (WKT)")
}
else if ( OSRIsGeographic(hSRS) )
{
firstTransformGiveGeo = true;
otbMsgDevMacro(<< "- Considering that the first transform gives geo")
}
else
{
firstTransformGiveGeo = false;
otbMsgDevMacro(<< "- Considering that the first transform does not give geo (fallback)")
}
OSRRelease(hSRS);
otbMsgDevMacro(<< "Input projection set to identity")
}
//*****************************
//Set the output transformation
//*****************************
if (!m_OutputProjectionRef.empty()) //map projection
{
typedef otb::GenericMapProjection<TransformDirection::FORWARD, ScalarType, InputSpaceDimension,
OutputSpaceDimension> ForwardMapProjectionType;
typename ForwardMapProjectionType::Pointer mapTransform = ForwardMapProjectionType::New();
mapTransform->SetWkt(m_OutputProjectionRef);
if (mapTransform->IsProjectionDefined())
{
m_OutputTransform = mapTransform.GetPointer();
outputTransformIsMap = true;
otbMsgDevMacro(<< "Output projection set to map transform: " << m_OutputTransform);
}
}
// If not, try to make a sensor model
if ((m_OutputTransform.IsNull()) && (m_OutputKeywordList.GetSize() > 0))
{
typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType;
typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New();
sensorModel->SetImageGeometry(m_OutputKeywordList);
if (sensorModel->IsValidSensorModel())
{
m_OutputTransform = sensorModel.GetPointer();
outputTransformIsSensor = true;
otbMsgDevMacro(<< "Output projection set to sensor model");
}
}
if (m_OutputTransform.IsNull()) //default if we didn't manage to instantiate it before
{
m_OutputTransform = itk::IdentityTransform<double, NOutputDimensions>::New();
if (firstTransformGiveGeo)
{
m_OutputProjectionRef =
"GEOGCS[\"GCS_WGS_1984\", DATUM[\"D_WGS_1984\", SPHEROID[\"WGS_1984\", 6378137, 298.257223563]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.017453292519943295]]";
}
otbMsgDevMacro(<< "Output projection set to identity");
}
m_Transform->SetFirstTransform(m_InputTransform);
m_Transform->SetSecondTransform(m_OutputTransform);
m_TransformUpToDate = true;
//The accuracy information is a simplistic model for now and should be refined
if ((inputTransformIsSensor || outputTransformIsSensor))
{
//Sensor model
m_TransformAccuracy = Projection::ESTIMATE;
}
else if (firstTransformGiveGeo && !outputTransformIsSensor && !outputTransformIsMap)
{
//The original image was in lon/lat and we did not change anything
m_TransformAccuracy = Projection::PRECISE;
}
else if (!inputTransformIsSensor && !outputTransformIsSensor && !inputTransformIsMap && !outputTransformIsMap)
{
//no transform
m_TransformAccuracy = Projection::UNKNOWN;
}
else
{
m_TransformAccuracy = Projection::PRECISE;
}
}
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::OutputPointType
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::TransformPoint(const InputPointType& point) const
{
InputPointType inputPoint = point;
// Apply input origin/spacing
inputPoint[0] = inputPoint[0] * m_InputSpacing[0] + m_InputOrigin[0];
inputPoint[1] = inputPoint[1] * m_InputSpacing[1] + m_InputOrigin[1];
// Transform point
OutputPointType outputPoint;
outputPoint = this->GetTransform()->TransformPoint(inputPoint);
// Apply output origin/spacing
outputPoint[0] = (outputPoint[0] - m_OutputOrigin[0]) / m_OutputSpacing[0];
outputPoint[1] = (outputPoint[1] - m_OutputOrigin[1]) / m_OutputSpacing[1];
// otbMsgDevMacro("GenericRSTransform: " << point << " -> " << outputPoint);
return outputPoint;
}
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
bool
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::GetInverse(Self * inverseTransform) const
{
// Test the inverseTransform pointer
if (inverseTransform == ITK_NULLPTR)
{
return false;
}
// Swich projection refs
inverseTransform->SetInputProjectionRef(m_OutputProjectionRef);
inverseTransform->SetOutputProjectionRef(m_InputProjectionRef);
// Switch keywordlists
inverseTransform->SetInputKeywordList(m_OutputKeywordList);
inverseTransform->SetOutputKeywordList(m_InputKeywordList);
// Switch dictionnaries
inverseTransform->SetInputDictionary(m_OutputDictionary);
inverseTransform->SetOutputDictionary(m_InputDictionary);
// Switch spacings
inverseTransform->SetInputSpacing(m_OutputSpacing);
inverseTransform->SetOutputSpacing(m_InputSpacing);
// Switch origins
inverseTransform->SetInputOrigin(m_OutputOrigin);
inverseTransform->SetOutputOrigin(m_InputOrigin);
// Instantiate transform
inverseTransform->InstantiateTransform();
return true;
}
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::InverseTransformBasePointer
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::GetInverseTransform() const
{
Self * inverseTransform = Self::New();
bool success = this->GetInverse(inverseTransform);
if (!success)
{
itkExceptionMacro(<< "Failed to create inverse transform");
}
return inverseTransform;
}
template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
void
GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Up to date: " << m_TransformUpToDate << std::endl;
if (m_TransformUpToDate)
{
os << indent << "Input transform: "<< std::endl;
m_InputTransform->Print(os, indent.GetNextIndent());
os << indent << "Output transform: " << std::endl;
m_OutputTransform->Print(os, indent.GetNextIndent());
}
else
{
os << indent << "Input transform: NULL" << std::endl;
os << indent << "Output transform: NULL" << std::endl;
}
os << indent << "Accuracy: "
<< (m_TransformAccuracy == Projection::PRECISE ?
"PRECISE" : (m_TransformAccuracy == Projection::ESTIMATE ?
"ESTIMATE" : "UNKNOWN")) << std::endl;
}
} // namespace otb
#endif
|