7 #include "fwActivities/validator/ImageProperties.hpp" 9 #include "fwActivities/validator/registry/macros.hpp" 11 #include <fwData/Composite.hpp> 12 #include <fwData/Image.hpp> 13 #include <fwData/Vector.hpp> 15 #include <fwMath/Compare.hpp> 17 #include <fwMedData/ImageSeries.hpp> 24 fwActivitiesValidatorRegisterMacro(
42 const ::fwActivities::registry::ActivityInfo& activityInfo,
43 const ::fwData::Vector::csptr& currentSelection )
const 47 if(currentSelection->size() > 1)
49 validation.first =
true;
50 validation.second =
"Input images have the same properties.";
52 ::fwMedData::ImageSeries::sptr imgSeries0 = ::fwMedData::ImageSeries::dynamicCast((*currentSelection)[0]);
53 SLM_ASSERT(
"Failed to retrieve an image series", imgSeries0);
54 ::fwData::Image::sptr img0 = imgSeries0->getImage();
55 SLM_ASSERT(
"Failed to retrieve image from image series", img0);
61 ::fwData::Vector::ContainerType::const_iterator it;
62 for(it = currentSelection->begin() + 1; it != currentSelection->end(); ++it)
64 ::fwMedData::ImageSeries::sptr imgSeries = ::fwMedData::ImageSeries::dynamicCast(*it);
65 SLM_ASSERT(
"Failed to retrieve an image series", imgSeries);
66 ::fwData::Image::sptr img = imgSeries->getImage();
67 SLM_ASSERT(
"Failed to retrieve an image data", img);
69 if ( size != img->getSize() ||
70 !::fwMath::isContainerEqual< const ::fwData::Image::SpacingType >(spacing, img->getSpacing()) ||
71 !::fwMath::isContainerEqual< const ::fwData::Image::OriginType >(origin, img->getOrigin()) )
73 std::string errorMsg =
"Images in selection have not the same properties :\n";
74 errorMsg += (size != img->getSize()) ?
"- size\n" :
"";
75 errorMsg += (spacing != img->getSpacing()) ?
"- spacing\n" :
"";
76 errorMsg += (origin != img->getOrigin()) ?
"- origin" :
"";
78 validation.first =
false;
79 validation.second = errorMsg;
87 validation.first =
true;
88 validation.second =
"Only one data provided to check images properties, assuming validation as ok.";
100 ::fwData::Vector::csptr vector = ::fwData::Vector::dynamicConstCast(currentData);
101 ::fwData::Composite::csptr composite = ::fwData::Composite::dynamicConstCast(currentData);
103 validation.first =
true;
104 validation.second =
"Input images have the same properties.";
106 ::fwData::Image::csptr img0;
110 for (::fwData::Object::sptr obj : *vector)
112 ::fwMedData::ImageSeries::csptr imgSeries = ::fwMedData::ImageSeries::dynamicConstCast(obj);
113 ::fwData::Image::csptr img = ::fwData::Image::dynamicConstCast(obj);
116 img = imgSeries->getImage();
127 if ( img0->getSize() != img->getSize() ||
128 !::fwMath::isContainerEqual< const ::fwData::Image::SpacingType >(img0->getSpacing(),
129 img->getSpacing()) ||
130 !::fwMath::isContainerEqual< const ::fwData::Image::OriginType >(img0->getOrigin(),
133 std::string errorMsg =
"Images in selection have not the same properties :\n";
134 errorMsg += (img0->getSize() != img->getSize()) ?
"- size\n" :
"";
135 errorMsg += (img0->getSpacing() != img->getSpacing()) ?
"- spacing\n" :
"";
136 errorMsg += (img0->getOrigin() != img->getOrigin()) ?
"- origin" :
"";
138 validation.first =
false;
139 validation.second = errorMsg;
147 validation.first =
false;
148 validation.second =
"Given data does not contain valid images.";
154 for (
auto elt : *composite)
156 ::fwMedData::ImageSeries::sptr imgSeries = ::fwMedData::ImageSeries::dynamicCast(elt.second);
157 ::fwData::Image::sptr img = ::fwData::Image::dynamicCast(elt.second);
160 img = imgSeries->getImage();
171 if ( img0->getSize() != img->getSize() ||
172 !::fwMath::isContainerEqual< const ::fwData::Image::SpacingType >(img0->getSpacing(),
173 img->getSpacing()) ||
174 !::fwMath::isContainerEqual< const ::fwData::Image::OriginType >(img0->getOrigin(),
177 std::string errorMsg =
"Images in selection have not the same properties :\n";
178 errorMsg += (img0->getSize() != img->getSize()) ?
"- size\n" :
"";
179 errorMsg += (img0->getSpacing() != img->getSpacing()) ?
"- spacing\n" :
"";
180 errorMsg += (img0->getOrigin() != img->getOrigin()) ?
"- origin" :
"";
182 validation.first =
false;
183 validation.second = errorMsg;
191 validation.first =
false;
192 validation.second =
"Given data does not contain valid images.";
198 validation.first =
false;
199 validation.second =
"Given data is not a Vector or Composite of images. The validation can not be performed.";
Defines a validator which checks that properties of given images are the same.
std::pair< bool, std::string > ValidationType
Defines validation result of an activity. First element tells if the activity is validated or not by ...
FWACTIVITIES_API ImageProperties(::fwActivities::IValidator::Key key)
Constructor. Do nothing.
virtual FWACTIVITIES_API ~ImageProperties()
Destructor. Do nothing.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWACTIVITIES_API IValidator::ValidationType validate(const ::fwActivities::registry::ActivityInfo &activityInfo, const std::shared_ptr< const ::fwData::Vector > ¤tSelection) const override
Validates if the given images have the same properties (origin, spacing, ...)
std::vector< double > SpacingType
Image spacing type.
Namespace containing activities data and builder.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
::fwData::Array::SizeType SizeType
Image size type.
std::vector< double > OriginType
Image origin type.