| 186 | }; |
| 187 | |
| 188 | ObjectPtr ImageDiffOp::doOperation( const CompoundObject * operands ) |
| 189 | { |
| 190 | ImagePrimitivePtr imageA = m_imageAParameter->getTypedValue< ImagePrimitive >(); |
| 191 | ImagePrimitivePtr imageB = m_imageBParameter->getTypedValue< ImagePrimitive >(); |
| 192 | |
| 193 | if ( imageA == imageB ) |
| 194 | { |
| 195 | msg( Msg::Warning, "ImageDiffOp", "Exact same image specified as both input parameters."); |
| 196 | return new BoolData( false ); |
| 197 | } |
| 198 | |
| 199 | if ( !imageA || !imageB ) |
| 200 | { |
| 201 | throw InvalidArgumentException( "ImageDiffOp: NULL image specified as input parameter" ); |
| 202 | } |
| 203 | |
| 204 | assert( imageA ); |
| 205 | assert( imageB ); |
| 206 | |
| 207 | if ( !imageA->channelsValid() || !imageB->channelsValid() ) |
| 208 | { |
| 209 | throw InvalidArgumentException( "ImageDiffOp: Image with invalid channels specified as input parameter" ); |
| 210 | } |
| 211 | |
| 212 | const bool alignDisplayWindows = m_alignDisplayWindowsParameter->getTypedValue(); |
| 213 | |
| 214 | if( alignDisplayWindows ) |
| 215 | { |
| 216 | /// Fail if the display windows are of a different width or height. |
| 217 | if ( ( imageA->getDisplayWindow().size().x != imageB->getDisplayWindow().size().x ) || ( imageA->getDisplayWindow().size().y != imageB->getDisplayWindow().size().y ) ) |
| 218 | { |
| 219 | return new BoolData( true ); |
| 220 | } |
| 221 | |
| 222 | // If the display windows are different to each other then we move them back to the origin. |
| 223 | if ( imageA->getDisplayWindow().min != imageB->getDisplayWindow().min || imageA->getDisplayWindow().min != Imath::V2i( 0 ) ) |
| 224 | { |
| 225 | Imath::V2i offsetA = imageA->getDisplayWindow().min; |
| 226 | Imath::Box2i displayWindowA( imageA->getDisplayWindow().min-offsetA, imageA->getDisplayWindow().max-offsetA ); |
| 227 | Imath::Box2i dataWindowA( imageA->getDataWindow().min-offsetA, imageA->getDataWindow().max-offsetA ); |
| 228 | imageA->setDisplayWindow( displayWindowA ); |
| 229 | imageA->setDataWindow( dataWindowA ); |
| 230 | |
| 231 | Imath::V2i offsetB = imageB->getDisplayWindow().min; |
| 232 | Imath::Box2i displayWindowB( imageB->getDisplayWindow().min-offsetB, imageB->getDisplayWindow().max-offsetB ); |
| 233 | Imath::Box2i dataWindowB( imageB->getDataWindow().min-offsetB, imageB->getDataWindow().max-offsetB ); |
| 234 | imageB->setDisplayWindow( displayWindowB ); |
| 235 | imageB->setDataWindow( dataWindowB ); |
| 236 | } |
| 237 | } |
| 238 | else if ( imageA->getDisplayWindow() != imageB->getDisplayWindow() ) |
| 239 | { |
| 240 | return new BoolData( true ); |
| 241 | } |
| 242 | |
| 243 | /// Use the CropOp to expand the dataWindows of both images to fill the display window |
| 244 | ImageCropOpPtr cropOp = new ImageCropOp(); |
| 245 | cropOp->matchDataWindowParameter()->setTypedValue( true ); |
nothing calls this directly
no test coverage detected