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

REFAC: use ImageMetadata in MultiDisparityMapTo3DFilter

parent 24ee6411
......@@ -1141,11 +1141,11 @@ private:
}
// transform disparity into 3D map
m_MultiDisparityTo3DFilterList[i]->SetReferenceKeywordList(inleft->GetImageKeywordlist());
m_MultiDisparityTo3DFilterList[i]->SetReferenceImageMetadata(&(inleft->GetImageMetadata()));
m_MultiDisparityTo3DFilterList[i]->SetNumberOfMovingImages(1);
m_MultiDisparityTo3DFilterList[i]->SetHorizontalDisparityMapInput(0, hDispOutput2);
m_MultiDisparityTo3DFilterList[i]->SetVerticalDisparityMapInput(0, vDispOutput2);
m_MultiDisparityTo3DFilterList[i]->SetMovingKeywordList(0, inright->GetImageKeywordlist());
m_MultiDisparityTo3DFilterList[i]->SetMovingImageMetadata(0, &(inright->GetImageMetadata()));
m_MultiDisparityTo3DFilterList[i]->SetDisparityMaskInput(0, translatedMaskImage);
m_MultiDisparityTo3DFilterList[i]->UpdateOutputInformation();
......
......@@ -94,8 +94,6 @@ public:
typedef typename PointSetType::PointsContainer PointsContainer;
typedef typename PointSetType::PointDataContainer LabelContainer;
typedef otb::ImageKeywordlist ImageKeywordListType;
typedef std::map<unsigned int, itk::ImageRegionConstIterator<DisparityMapType>> DispMapIteratorList;
typedef std::map<unsigned int, itk::ImageRegionConstIterator<MaskImageType>> MaskIteratorList;
......@@ -126,24 +124,24 @@ public:
const TResidueImage* GetResidueOutput() const;
TResidueImage* GetResidueOutput();
/** Set keywordlist of the reference image */
void SetReferenceKeywordList(const ImageKeywordListType kwl)
/** Set ImageMetadata of the reference image */
void SetReferenceImageMetadata(const ImageMetadata* imd)
{
this->m_ReferenceKeywordList = kwl;
this->m_ReferenceImageMetadata = imd;
this->Modified();
}
/** Get keywordlist of the reference image */
const ImageKeywordListType& GetReferenceKeywordList() const
/** Get ImageMetadata of the reference image */
const ImageMetadata* GetReferenceImageMetadata() const
{
return this->m_ReferenceKeywordList;
return this->m_ReferenceImageMetadata;
}
/** Set keywordlist of the moving image 'index' */
void SetMovingKeywordList(unsigned int index, const ImageKeywordListType kwl);
/** Set ImageMetadata of the moving image 'index' */
void SetMovingImageMetadata(unsigned int index, const ImageMetadata* imd);
/** Get keywordlist of the moving image 'index' */
const ImageKeywordListType& GetMovingKeywordList(unsigned int index) const;
/** Get ImageMetadata of the moving image 'index' */
const ImageMetadata* GetMovingImageMetadata(unsigned int index) const;
protected:
/** Constructor */
......@@ -168,17 +166,19 @@ private:
MultiDisparityMapTo3DFilter(const Self&) = delete;
void operator=(const Self&) = delete;
/** Keywordlist of reference sensor image */
ImageKeywordListType m_ReferenceKeywordList;
/** Keywordlists of moving sensor images */
std::vector<ImageKeywordListType> m_MovingKeywordLists;
/** Reference sensor image transform */
RSTransformType::Pointer m_ReferenceToGroundTransform;
/** Moving sensor image transforms */
std::vector<RSTransformType::Pointer> m_MovingToGroundTransform;
/** ImageMetadata of reference sensor image */
const ImageMetadata* m_ReferenceImageMetadata = nullptr;
/** ImageMetadata of moving sensor images */
std::vector<const ImageMetadata*> m_MovingImageMetadatas;
};
} // end namespace otb
......
......@@ -34,7 +34,7 @@ MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueI
// Set the number of inputs (1 moving image by default -> 3 inputs)
this->SetNumberOfRequiredInputs(3);
this->SetNumberOfRequiredInputs(1);
this->m_MovingKeywordLists.resize(1);
this->m_MovingImageMetadatas.resize(1);
// Set the outputs
this->SetNumberOfRequiredOutputs(2);
......@@ -53,14 +53,14 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
if (nb > 0)
{
this->SetNumberOfRequiredInputs(3 * nb);
this->m_MovingKeywordLists.resize(nb);
this->m_MovingImageMetadatas.resize(nb);
}
}
template <class TDisparityImage, class TOutputImage, class TMaskImage, class TResidueImage>
unsigned int MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::GetNumberOfMovingImages()
{
return this->m_MovingKeywordLists.size();
return this->m_MovingImageMetadatas.size();
}
template <class TDisparityImage, class TOutputImage, class TMaskImage, class TResidueImage>
......@@ -143,24 +143,24 @@ TResidueImage* MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskI
}
template <class TDisparityImage, class TOutputImage, class TMaskImage, class TResidueImage>
void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::SetMovingKeywordList(unsigned int index,
const ImageKeywordListType kwl)
void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::SetMovingImageMetadata(unsigned int index,
const ImageMetadata* imd)
{
if (this->m_MovingKeywordLists.size() > index)
if (this->m_MovingImageMetadatas.size() > index)
{
this->m_MovingKeywordLists[index] = kwl;
this->m_MovingImageMetadatas[index] = imd;
}
}
template <class TDisparityImage, class TOutputImage, class TMaskImage, class TResidueImage>
const typename MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::ImageKeywordListType&
MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::GetMovingKeywordList(unsigned int index) const
const ImageMetadata*
MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TResidueImage>::GetMovingImageMetadata(unsigned int index) const
{
if (this->m_MovingKeywordLists.size() <= index)
if (this->m_MovingImageMetadatas.size() <= index)
{
itkExceptionMacro(<< "Keywordlist index is outside the container");
itkExceptionMacro(<< "ImageMetadata index is outside the container");
}
return this->m_MovingKeywordLists[index];
return this->m_MovingImageMetadatas[index];
}
template <class TDisparityImage, class TOutputImage, class TMaskImage, class TResidueImage>
......@@ -185,14 +185,17 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
residuePtr->SetOrigin(horizDisp->GetOrigin());
residuePtr->SetSignedSpacing(horizDisp->GetSignedSpacing());
if (this->m_ReferenceKeywordList.GetSize() > 0)
if (this->m_ReferenceImageMetadata)
{
itk::EncapsulateMetaData<ImageKeywordListType>(outputPtr->GetMetaDataDictionary(), MetaDataKey::OSSIMKeywordlistKey, this->m_ReferenceKeywordList);
itk::EncapsulateMetaData<ImageKeywordListType>(residuePtr->GetMetaDataDictionary(), MetaDataKey::OSSIMKeywordlistKey, this->m_ReferenceKeywordList);
auto outputmetadata = *m_ReferenceImageMetadata;
// Don't copy band metadata, as output bands are not related to input bands.
outputmetadata.Bands.clear();
outputPtr->SetImageMetadata(outputmetadata);
residuePtr->SetImageMetadata(outputmetadata);
}
else
{
itkExceptionMacro(<< "Reference keywordlist is missing");
itkExceptionMacro(<< "Reference ImageMetadata is missing");
}
}
else
......@@ -264,12 +267,12 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
}
}
// Check moving keywordlist
for (unsigned int k = 0; k < this->m_MovingKeywordLists.size(); ++k)
// Check moving ImageMetadata
for (unsigned int k = 0; k < this->m_MovingImageMetadatas.size(); ++k)
{
if (this->m_MovingKeywordLists[k].GetSize() == 0)
if (!this->m_MovingImageMetadatas[k])
{
itkExceptionMacro(<< "Keywordlist of moving image at position " << k << " is empty");
itkExceptionMacro(<< "ImageMetadata of moving image at position " << k << " is empty");
}
}
}
......@@ -279,16 +282,15 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
{
// Instantiate all transforms
this->m_ReferenceToGroundTransform = RSTransformType::New();
//TODO OSSIM: replace KeywordList by ImageMetadata
//this->m_ReferenceToGroundTransform->SetInputKeywordList(this->m_ReferenceKeywordList);
this->m_ReferenceToGroundTransform->SetInputImageMetadata(this->m_ReferenceImageMetadata);
this->m_ReferenceToGroundTransform->InstantiateTransform();
this->m_MovingToGroundTransform.clear();
for (unsigned int k = 0; k < this->m_MovingKeywordLists.size(); ++k)
for (unsigned int k = 0; k < this->m_MovingImageMetadatas.size(); ++k)
{
RSTransformType::Pointer transfo = RSTransformType::New();
//TODO OSSIM: replace KeywordList by ImageMetadata
//transfo->SetInputKeywordList(this->m_MovingKeywordLists[k]);
transfo->SetInputImageMetadata(this->m_MovingImageMetadatas[k]);
transfo->InstantiateTransform();
this->m_MovingToGroundTransform.push_back(transfo);
}
......@@ -310,7 +312,7 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
DispMapIteratorList vDispIts;
MaskIteratorList maskIts;
for (unsigned int k = 0; k < this->m_MovingKeywordLists.size(); ++k)
for (unsigned int k = 0; k < this->m_MovingImageMetadatas.size(); ++k)
{
// Iterators over horizontal disparity maps
hDispIts[k] = itk::ImageRegionConstIterator<DisparityMapType>(this->GetHorizontalDisparityMapInput(k), outputRegionForThread);
......@@ -369,7 +371,7 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
unsigned int nbPoints = 1;
for (unsigned int k = 0; k < this->m_MovingKeywordLists.size(); ++k)
for (unsigned int k = 0; k < this->m_MovingImageMetadatas.size(); ++k)
{
// Compute the N moving lines of sight
TDPointType pointAi, pointBi;
......@@ -388,10 +390,8 @@ void MultiDisparityMapTo3DFilter<TDisparityImage, TOutputImage, TMaskImage, TRes
currentPoint[2] = altiMax;
pointAi = this->m_MovingToGroundTransform[k]->TransformPoint(currentPoint);
currentPoint[2] = altiMin;
pointBi = this->m_MovingToGroundTransform[k]->TransformPoint(currentPoint);
pointSetA->SetPoint(nbPoints, pointAi);
pointSetB->SetPoint(nbPoints, pointBi);
pointSetA->SetPointData(nbPoints, k + 1);
......
......@@ -84,19 +84,19 @@ int otbMultiDisparityMapTo3DFilter(int argc, char* argv[])
vectorToListFilter2->UpdateOutputInformation();
Multi3DFilterType::Pointer multiFilter = Multi3DFilterType::New();
multiFilter->SetReferenceKeywordList(masterReader->GetOutput()->GetImageKeywordlist());
multiFilter->SetReferenceImageMetadata(&(masterReader->GetOutput()->GetImageMetadata()));
multiFilter->SetNumberOfMovingImages(2);
multiFilter->SetHorizontalDisparityMapInput(0, vectorToListFilter1->GetOutput()->GetNthElement(0));
multiFilter->SetVerticalDisparityMapInput(0, vectorToListFilter1->GetOutput()->GetNthElement(1));
multiFilter->SetDisparityMaskInput(0, mask1Reader->GetOutput());
multiFilter->SetMovingKeywordList(0, slave1Reader->GetOutput()->GetImageKeywordlist());
multiFilter->SetMovingImageMetadata(0, &(slave1Reader->GetOutput()->GetImageMetadata()));
multiFilter->SetHorizontalDisparityMapInput(1, vectorToListFilter2->GetOutput()->GetNthElement(0));
multiFilter->SetVerticalDisparityMapInput(1, vectorToListFilter2->GetOutput()->GetNthElement(1));
multiFilter->SetDisparityMaskInput(1, mask2Reader->GetOutput());
multiFilter->SetMovingKeywordList(1, slave2Reader->GetOutput()->GetImageKeywordlist());
multiFilter->SetMovingImageMetadata(1, &(slave2Reader->GetOutput()->GetImageMetadata()));
WriterType::Pointer writer = WriterType::New();
writer->SetInput(multiFilter->GetOutput());
......
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