Commit 9bf94dd4 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Using the right elevation setup in all applications

parent 12a20af9
......@@ -146,29 +146,8 @@ private:
vprojIm->SetInputVectorData(inVectorData);
vprojIm->SetInputImage(inImage);
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
vprojIm->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
vprojIm->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
vprojIm->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
vprojIm->SetUseOutputSpacingAndOriginFromImage(true); // we want index as input;
vprojIm->Update();
......@@ -271,26 +250,8 @@ private:
vproj->SetOutputOrigin(inImage->GetOrigin());
vproj->SetOutputSpacing(inImage->GetSpacing());
// Elevation through the elevation handler
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
vproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
vproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
vproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
vproj->Update();
m_ProjectedVectorData = vproj->GetOutput();
......
......@@ -260,29 +260,8 @@ private:
vdreproj->SetInput(vectorData);
vdreproj->SetUseOutputSpacingAndOriginFromImage(false);
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
vdreproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
vdreproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
vdreproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
vdreproj->Update();
......
......@@ -205,30 +205,8 @@ private:
vdreproj->SetInput(vectorData);
vdreproj->SetUseOutputSpacingAndOriginFromImage(false);
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
vdreproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
vdreproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
vdreproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
vdreproj->Update();
//Sample list generator
......
......@@ -157,23 +157,8 @@ private:
m_DispToElev->SetDisparityMaskInput(this->GetParameterUInt8Image("io.mask"));
}
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_DispToElev->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_DispToElev->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_DispToElev->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
m_DispToElev->UpdateOutputInformation();
FloatVectorImageType::RegionType outputRegion = m_DispToElev->GetOutput()->GetLargestPossibleRegion();
......
......@@ -128,25 +128,13 @@ private:
AddParameter(ParameterType_Group,"epi","Epipolar geometry and grid parameters");
SetParameterDescription("epi","Parameters of the epipolar geometry and output grids");
AddParameter(ParameterType_Choice,"epi.elevation","Elevation management");
SetParameterDescription("epi.elevation","Manage elevation source for stereo-rectification");
AddChoice("epi.elevation.avg","User-defined average elevation");
SetParameterDescription("epi.elevation.avg","Average elevation defined by user");
ElevationParametersHandler::AddElevationParameters(this, "epi.elevation");
AddParameter(ParameterType_Float,"epi.elevation.avg.value","Average elevation value");
SetParameterDescription("epi.elevation.avg.value","Average elevation value");
AddChoice("epi.elevation.avgdem","Average elevation computed from DEM");
AddParameter(ParameterType_Empty,"epi.elevation.avgdem","Average elevation computed from DEM");
SetParameterDescription("epi.elevation.avgdem","Average elevation computed from the provided DEM");
MandatoryOff("epi.elevation.avgdem");
AddParameter(ParameterType_Directory,"epi.elevation.avgdem.path","DEM directory");
SetParameterDescription("epi.elevation.avgdem.path","Path to the DEM directory");
AddParameter(ParameterType_InputFilename,"epi.elevation.avgdem.geoid","Geoid file");
SetParameterDescription("epi.elevation.avgdem.geoid","Path to the geoid file");
MandatoryOff("epi.elevation.avgdem.geoid");
AddParameter(ParameterType_Int,"epi.elevation.avgdem.step","Sub-sampling step");
AddParameter(ParameterType_Int,"epi.elevation.avgdem.step","Sub-sampling step");
SetParameterDescription("epi.elevation.avgdem.step","Step of sub-sampling for average elevation estimation");
SetDefaultParameterInt("epi.elevation.avgdem.step",1);
SetMinimumParameterIntValue("epi.elevation.avgdem.step",1);
......@@ -166,16 +154,6 @@ private:
SetParameterRole("epi.elevation.avgdem.maxdisp",Role_Output);
DisableParameter("epi.elevation.avgdem.maxdisp");
AddChoice("epi.elevation.dem","Elevation from DEM");
SetParameterDescription("epi.elevation.dem","Local elevations from the provided DEM");
AddParameter(ParameterType_Directory,"epi.elevation.dem.path","DEM directory");
SetParameterDescription("epi.elevation.dem.path","Path to the DEM directory");
AddParameter(ParameterType_InputFilename,"epi.elevation.dem.geoid","Geoid file");
SetParameterDescription("epi.elevation.dem.geoid","Path to the geoid file");
MandatoryOff("epi.elevation.dem.geoid");
AddParameter(ParameterType_Float,"epi.scale","Scale of epipolar images");
SetParameterDescription("epi.scale","The scale parameter allows to generated zoomed-in (scale < 1) or zoomed-out (scale > 1) epipolar images.");
SetDefaultParameterFloat("epi.scale",1.);
......@@ -232,12 +210,10 @@ private:
m_DeformationFieldSource->SetGridStep(GetParameterInt("epi.step"));
m_DeformationFieldSource->SetScale(GetParameterFloat("epi.scale"));
if(GetParameterString("epi.elevation") == "avg")
{
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"epi.elevation");
m_DeformationFieldSource->SetAverageElevation(GetParameterFloat("epi.elevation.avg.value"));
}
else if(GetParameterString("epi.elevation") == "avgdem")
if(IsParameterEnabled("epi.elevation.avgdem"))
{
// TODO: Implement me
FloatImageType::PointType origin = GetParameterImage("io.inleft")->GetOrigin();
......@@ -249,7 +225,6 @@ private:
spacing[0]*=GetParameterInt("epi.elevation.avgdem.step");
spacing[1]*=GetParameterInt("epi.elevation.avgdem.step");
m_DEMToImageGenerator->SetDEMDirectoryPath(GetParameterString("epi.elevation.avgdem.path"));
m_DEMToImageGenerator->SetOutputOrigin(origin);
m_DEMToImageGenerator->SetOutputSize(size);
m_DEMToImageGenerator->SetOutputSpacing(spacing);
......@@ -260,30 +235,16 @@ private:
m_DEMToImageGenerator->AboveEllipsoidOn();
if(IsParameterEnabled("epi.elevation.avgdem.geoid"))
{
m_DEMToImageGenerator->SetGeoidFile(GetParameterString("epi.elevation.avgdem.geoid"));
}
m_StatisticsFilter->SetInput(m_DEMToImageGenerator->GetOutput());
AddProcess(m_StatisticsFilter,"Computing DEM statistics ...");
m_StatisticsFilter->Update();
m_DeformationFieldSource->SetAverageElevation(m_StatisticsFilter->GetMean());
otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(m_StatisticsFilter->GetMean());
EnableParameter("epi.elevation.avgdem.value");
SetParameterFloat("epi.elevation.avgdem.value",m_StatisticsFilter->GetMean());
}
else if(GetParameterString("epi.elevation") == "dem")
{
m_DeformationFieldSource->SetDEMDirectory(GetParameterString("epi.elevation.dem.path"));
if(IsParameterEnabled("epi.elevation.dem.geoid"))
{
m_DeformationFieldSource->SetGeoidFile(GetParameterString("epi.elevation.dem.geoid"));
}
}
AddProcess(m_DeformationFieldSource, "Computing epipolar grids ...");
......
......@@ -218,30 +218,8 @@ private:
m_StereoFilter->SetSlaveInput(m_Intensity2->GetOutput());
}
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_StereoFilter->SetUseDEM(true);
m_StereoFilter->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_StereoFilter->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_StereoFilter->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
m_StereoFilter->SetSubtractInitialElevation(subtractInitialHeight);
......
......@@ -283,27 +283,8 @@ private:
extractChannel2->SetInput(this->GetParameterImage("in2"));
extractChannel2->SetChannel(GetParameterInt("band2"));
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
rsTransform->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
rsTransform->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
rsTransform2ToWGS84->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
rsTransform2ToWGS84->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
rsTransform->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
rsTransform2ToWGS84->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
rsTransform->InstanciateTransform();
rsTransform2ToWGS84->InstanciateTransform();
......
......@@ -169,29 +169,8 @@ private:
//vproj->SetInputOrigin(GetParameterImage("in")->GetOrigin());
//vproj->SetInputSpacing(GetParameterImage("in")->GetSpacing());
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
vproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
vproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
vproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
AddProcess(vproj, "Reprojecting output vector data");
vproj->Update();
......
......@@ -126,29 +126,8 @@ private:
InterpolatorType::Pointer interpolator = InterpolatorType::New();
resampler->SetInterpolator(interpolator);
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
resampler->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
resampler->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
resampler->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
// Set up output image informations
FloatVectorImageType::SpacingType spacing = panchro->GetSpacing();
......
......@@ -98,30 +98,8 @@ private:
m_Envelope->SetInput(input);
m_Envelope->SetSamplingRate(GetParameterInt("sr"));
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_Envelope->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_Envelope->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_Envelope->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
if (HasValue("proj"))
{
m_Envelope->SetOutputProjectionRef(GetParameterString("proj"));
......
......@@ -387,29 +387,8 @@ private:
break;
}
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_ResampleFilter->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_ResampleFilter->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_ResampleFilter->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
// If activated, generate RPC model
if(IsParameterEnabled("opt.rpc"))
......
......@@ -96,34 +96,15 @@ private:
otb::SensorModelAdapter::Pointer sm_ref = otb::SensorModelAdapter::New();
// Read the geom file
bool canRead = sm->ReadGeomFile(GetParameterString("ingeom"));
canRead = sm_ref->ReadGeomFile(GetParameterString("ingeom"));
sm->ReadGeomFile(GetParameterString("ingeom"));
sm_ref->ReadGeomFile(GetParameterString("ingeom"));
// Setup elevation
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
otb::DEMHandler::Pointer demHandler = otb::DEMHandler::Instance();
double avg_elevation = 0;
bool use_avg_elevation = false;
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
demHandler->OpenDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
demHandler->OpenGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
avg_elevation = ElevationParametersHandler::GetAverageElevation(this, "elev");
use_avg_elevation = true;
}
break;
}
// Parse the input file for ground control points
std::ifstream ifs;
ifs.open(GetParameterString("inpoints").c_str());
// Parse the input file for ground control points
std::ifstream ifs;
ifs.open(GetParameterString("inpoints").c_str());
TiePointsType tiepoints;
......@@ -151,10 +132,7 @@ private:
nextpos = line.find_first_of("\t", pos);
lat = atof(line.substr(pos, nextpos).c_str());
if(!use_avg_elevation)
z = demHandler->GetHeightAboveEllipsoid(lon,lat);
else
z = avg_elevation;
z = otb::DEMHandler::Instance()->GetHeightAboveEllipsoid(lon,lat);
otbAppLogINFO("Adding tie point x="<<x<<", y="<<y<<", z="<<z<<", lon="<<lon<<", lat="<<lat);
......
......@@ -107,29 +107,8 @@ private:
m_Interpolator = InterpolatorType::New();
m_Resampler->SetInterpolator(m_Interpolator);
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_Resampler->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_Resampler->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_Resampler->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
// Set up output image informations
UInt16VectorImageType::SpacingType spacing = refImage->GetSpacing();
......
......@@ -168,30 +168,8 @@ private:
//m_Vproj->SetInputOrigin(inputImage->GetOrigin());
//m_Vproj->SetInputSpacing(inputImage->GetSpacing());
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))
{
case Elevation_DEM:
{
m_Vproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
m_Vproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
}
break;
case Elevation_Average:
{
m_Vproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
}
break;
// Commented cause using a tiff file is not implemented yet
// case Elevation_Tiff:
// {
// }
// break;
}
}
// Setup the DEM Handler
otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");
m_Vproj->Update();
projectedVD = m_Vproj->GetOutput();
......
......@@ -99,29 +99,8 @@ private:
kmzWriter->SetInput( this->GetParameterImage("in") );
kmzWriter->SetPath( this->GetParameterString("out") );
// Elevation through the elevation handler
if (ElevationParametersHandler::IsElevationEnabled(this, "elev"))
{
switch(ElevationParametersHandler::GetElevationType(this, "elev"))