Commit ff1ffe0
Simon Rit
BUG: Remove const_cast from VariableLengthVector constructor
The `Get` function of `VectorImage` iterators calls the
`VariableLengthVector` constructor parameterized by a const pointer and
a vector length (see `DefaultVectorPixelAccessor::Get`). The `m_Data`
pointer of the constructed VariableLengthVector which was returned was
then pointing to the returned pixel data. This led to an unexpected
behavior in `CastImageFilter::DynamicThreadedGenerateDataDispatched`
where modifications to the local variable
```
OutputPixelType value{ outputIt.Get() };
```
of `CastImageFilter::DynamicThreadedGenerateDataDispatched` were
actually modifying the pixel of the image at the iterator position.
The problem might occur elsewhere so it is safer to copy the data when a
VariableLengthVector is constructed from a const pointer despite the
potential loss in performances.
A `CastImageFilter` test has been added to illustrate the issue: when a
`VectorImage` was casted to an `Image< Vector <`, the first pixel of the
region was taking the value of the last pixel of the region. The test
illustrated this by creating an image filled with 0 except the first
pixel. The casted image was completely full of 0 before bug correction.1 parent a8dd05b commit ff1ffe0
File tree
2 files changed
+58
-2
lines changed- Modules
- Core/Common/include
- Filtering/ImageFilterBase/test
2 files changed
+58
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
403 | 447 | | |
404 | 448 | | |
405 | 449 | | |
| |||
431 | 475 | | |
432 | 476 | | |
433 | 477 | | |
| 478 | + | |
434 | 479 | | |
435 | 480 | | |
436 | 481 | | |
| |||
0 commit comments