MCPcopy Create free account
hub / github.com/ImageEngine/cortex / modify

Method modify

src/IECoreImage/ImageCropOp.cpp:228–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226};
227
228void ImageCropOp::modify( Object *object, const CompoundObject *operands )
229{
230 ImagePrimitive *image = runTimeCast<ImagePrimitive>( object );
231
232 // Validate the input image
233 if ( !image->channelsValid() )
234 {
235 throw InvalidArgumentException( "ImageCropOp: Input image is not valid" );
236 }
237
238 const Imath::Box2i &cropBox = m_cropBoxParameter->getTypedValue();
239 if ( cropBox.isEmpty() )
240 {
241 throw InvalidArgumentException( "ImageCropOp: Specified crop box is empty" );
242 }
243
244 const bool resetOrigin = m_resetOriginParameter->getTypedValue();
245 const bool intersect = m_intersectParameter->getTypedValue();
246
247 Imath::Box2i croppedDisplayWindow;
248 if ( intersect )
249 {
250 croppedDisplayWindow = boxIntersection( cropBox, image->getDisplayWindow() );
251 }
252 else
253 {
254 croppedDisplayWindow = cropBox;
255 }
256 const Imath::Box2i &dataWindow = image->getDataWindow();
257
258 Imath::Box2i croppedDataWindow = boxIntersection( cropBox, dataWindow );
259
260 Imath::Box2i newDisplayWindow = croppedDisplayWindow;
261 Imath::Box2i newDataWindow;
262
263 const bool matchDataWindow = m_matchDataWindowParameter->getTypedValue();
264 if ( matchDataWindow )
265 {
266 newDataWindow = newDisplayWindow;
267 }
268 else
269 {
270 newDataWindow = croppedDataWindow;
271 }
272
273 for( auto &channel : image->channels )
274 {
275 ImageCropFn fn( dataWindow, croppedDataWindow, newDataWindow );
276 DataPtr data = channel.second;
277 assert( data );
278
279 channel.second = despatchTypedData< ImageCropFn, TypeTraits::IsNumericVectorTypedData >( data.get(), fn );
280 assert( channel.second );
281 }
282
283 if ( resetOrigin )
284 {
285#ifndef NDEBUG

Callers

nothing calls this directly

Calls 7

InvalidArgumentExceptionFunction · 0.85
channelsValidMethod · 0.80
setDataWindowMethod · 0.80
setDisplayWindowMethod · 0.80
isEmptyMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected