/usr/include/ITK-4.5/itkVideoStream.hxx is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 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 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __itkVideoStream_hxx
#define __itkVideoStream_hxx
#include "itkVideoStream.h"
namespace itk
{
//-PUBLIC METHODS--------------------------------------------------------------
//
// SetFrameLargestPossibleSpatialRegion
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameLargestPossibleSpatialRegion(
SizeValueType frameNumber, typename TFrameType::RegionType region)
{
m_LargestPossibleSpatialRegionCache[frameNumber] = region;
// If the frame is currently buffered, set the actual frame's region
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetLargestPossibleRegion(region);
}
}
//
// GetFrameLargestPossibleSpatialRegion
//
template<typename TFrameType>
const typename TFrameType::RegionType &
VideoStream<TFrameType>::
GetFrameLargestPossibleSpatialRegion(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_LargestPossibleSpatialRegionCache[frameNumber];
}
//
// SetFrameRequestedSpatialRegion
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameRequestedSpatialRegion(
SizeValueType frameNumber, typename TFrameType::RegionType region)
{
m_RequestedSpatialRegionCache[frameNumber] = region;
// If the frame is currently buffered, set the actual frame's region
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetRequestedRegion(region);
}
}
//
// GetFrameRequestedSpatialRegion
//
template<typename TFrameType>
const typename TFrameType::RegionType &
VideoStream<TFrameType>::
GetFrameRequestedSpatialRegion(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_RequestedSpatialRegionCache[frameNumber];
}
//
// SetFrameBufferedSpatialRegion
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameBufferedSpatialRegion(
SizeValueType frameNumber, typename TFrameType::RegionType region)
{
m_BufferedSpatialRegionCache[frameNumber] = region;
// If the frame is currently buffered, set the actual frame's region
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetBufferedRegion(region);
}
}
//
// GetFrameBufferedSpatialRegion
//
template<typename TFrameType>
const typename TFrameType::RegionType &
VideoStream<TFrameType>::
GetFrameBufferedSpatialRegion(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_BufferedSpatialRegionCache[frameNumber];
}
//
// SetFrameSpacing
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameSpacing(
SizeValueType frameNumber, typename TFrameType::SpacingType spacing)
{
// Make sure spacing is non-zero
for (unsigned int i = 0; i < FrameType::ImageDimension; ++i)
{
if (spacing[i] == 0.0)
{
itkExceptionMacro("Zero spacing is not allowed for any dimension: Spacing is " << spacing);
}
}
m_SpacingCache[frameNumber] = spacing;
// If the frame is currently buffered, set the actual frame's spacing
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetSpacing(spacing);
}
}
//
// GetFrameSpacing
//
template<typename TFrameType>
const typename TFrameType::SpacingType &
VideoStream<TFrameType>::
GetFrameSpacing(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_SpacingCache[frameNumber];
}
//
// SetFrameOrigin
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameOrigin(
SizeValueType frameNumber, typename TFrameType::PointType origin)
{
m_OriginCache[frameNumber] = origin;
// If the frame is currently buffered, set the actual frame's spacing
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetOrigin(origin);
}
}
//
// GetFrameOrigin
//
template<typename TFrameType>
const typename TFrameType::PointType &
VideoStream<TFrameType>::
GetFrameOrigin(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_OriginCache[frameNumber];
}
//
// SetFrameDirection
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameDirection(
SizeValueType frameNumber, typename TFrameType::DirectionType direction)
{
// Determinant is non-zero
if (vnl_math_abs(vnl_determinant(direction.GetVnlMatrix())) <= vnl_math::eps)
{
itkExceptionMacro("Bad direction, determinant is 0. Direction is " << direction);
}
m_DirectionCache[frameNumber] = direction;
// If the frame is currently buffered, set the actual frame's spacing
SizeValueType bufStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufDur = m_BufferedTemporalRegion.GetFrameDuration();
if (frameNumber >= bufStart && frameNumber < bufStart + bufDur)
{
FrameType* frame = this->GetFrame(frameNumber);
frame->SetDirection(direction);
}
}
//
// GetFrameOrigin
//
template<typename TFrameType>
const typename TFrameType::DirectionType &
VideoStream<TFrameType>::
GetFrameDirection(SizeValueType frameNumber) const
{
// It seems that std::map's [] operator isn't const correct, so we need to
// access this member from an non-const version of ourselves
return const_cast<Self*>(this)->m_DirectionCache[frameNumber];
}
//
// SetFrameBuffer
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrameBuffer(
typename VideoStream<TFrameType>::BufferType* buffer)
{
// We reinterpret the buffer to match TemporalDataObject's buffer type. We
// assume that any tampering with the internal buffer will use our BufferType
// so this will be safe.
TemporalDataObject::BufferType* castBuffer =
reinterpret_cast<TemporalDataObject::BufferType*>(buffer);
if (m_DataObjectBuffer != castBuffer)
{
m_DataObjectBuffer = castBuffer;
this->Modified();
}
}
//
// SetMinimumBufferSize
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetMinimumBufferSize(SizeValueType minimumNumberOfFrames)
{
// If we don't have enough buffer space to handle the number of requested
// frames, we need to resize the ring buffer. Just resizing can cause data to
// be in the wrong place. For example if the head of the buffer is at index 0
// and the buffer has 3 slots, setting frame number 3 will actually place the
// data into slot 0. If we then resize the buffer to have 4 slots, the data
// for frame 3 will live in slot 0 even though a request for frame 3 will
// return the data from the newly created slot 3. To circumvent this problem,
// we move the buffered data to the proper indices in the ring buffer after
// resizing.
if (m_DataObjectBuffer->GetNumberOfBuffers() < minimumNumberOfFrames)
{
// Save the indices of all frames in the currently buffered region
SizeValueType bufferedStart = m_BufferedTemporalRegion.GetFrameStart();
SizeValueType bufferedDuration = m_BufferedTemporalRegion.GetFrameDuration();
std::map<SizeValueType, DataObject*> frameNumPtrMap;
for (SizeValueType i = bufferedStart; i < bufferedStart + bufferedDuration; ++i)
{
frameNumPtrMap[i] = m_DataObjectBuffer->GetBufferContents(i);
}
// Resize the ring buffer
m_DataObjectBuffer->SetNumberOfBuffers(minimumNumberOfFrames);
// Move previously buffered data to the locations where their frame numbers now map
for (SizeValueType i = bufferedStart; i < bufferedStart + bufferedDuration; ++i)
{
m_DataObjectBuffer->SetBufferContents(i, frameNumPtrMap[i]);
}
}
}
//
// InitializeEmptyFrames
//
template<typename TFrameType>
void
VideoStream<TFrameType>::InitializeEmptyFrames()
{
// If we don't have any frames requested, just return
SizeValueType numFrames = m_RequestedTemporalRegion.GetFrameDuration();
if (numFrames == 0)
{
return;
}
// Safely expand the ring buffer if necessary
this->SetMinimumBufferSize(numFrames);
// Go through the number of required frames and make sure none are empty
SizeValueType startFrame = m_RequestedTemporalRegion.GetFrameStart();
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
if (!m_DataObjectBuffer->BufferIsFull(i))
{
FramePointer newFrame = FrameType::New();
FrameType* newFrameRawPointer = newFrame.GetPointer();
typename BufferType::ElementPointer element =
dynamic_cast<typename BufferType::ElementType*>(newFrameRawPointer);
m_DataObjectBuffer->SetBufferContents(i, element);
}
// Check to see if any cached meta data exists and if it does, assign it
if (m_LargestPossibleSpatialRegionCache.find(i) !=
m_LargestPossibleSpatialRegionCache.end())
{
this->GetFrame(i)->SetLargestPossibleRegion(m_LargestPossibleSpatialRegionCache[i]);
}
if (m_RequestedSpatialRegionCache.find(i) !=
m_RequestedSpatialRegionCache.end())
{
this->GetFrame(i)->SetRequestedRegion(m_RequestedSpatialRegionCache[i]);
}
if (m_BufferedSpatialRegionCache.find(i) !=
m_BufferedSpatialRegionCache.end())
{
this->GetFrame(i)->SetBufferedRegion(m_BufferedSpatialRegionCache[i]);
}
if (m_SpacingCache.find(i) != m_SpacingCache.end())
{
this->GetFrame(i)->SetSpacing(m_SpacingCache[i]);
}
if (m_OriginCache.find(i) != m_OriginCache.end())
{
this->GetFrame(i)->SetOrigin(m_OriginCache[i]);
}
if (m_DirectionCache.find(i) != m_DirectionCache.end())
{
this->GetFrame(i)->SetDirection(m_DirectionCache[i]);
}
}
}
//
// SetFrame
//
template<typename TFrameType>
void
VideoStream<TFrameType>::SetFrame(SizeValueType frameNumber,
FramePointer frame)
{
typename BufferType::ElementType* dataObjectRawPointer =
dynamic_cast<typename BufferType::ElementType*>(frame.GetPointer());
typename BufferType::ElementPointer dataObject = dataObjectRawPointer;
m_DataObjectBuffer->SetBufferContents(frameNumber,dataObject);
// Cache the meta data
m_LargestPossibleSpatialRegionCache[frameNumber] = frame->GetLargestPossibleRegion();
m_RequestedSpatialRegionCache[frameNumber] = frame->GetRequestedRegion();
m_BufferedSpatialRegionCache[frameNumber] = frame->GetBufferedRegion();
m_SpacingCache[frameNumber] = frame->GetSpacing();
m_OriginCache[frameNumber] = frame->GetOrigin();
m_DirectionCache[frameNumber] = frame->GetDirection();
}
//
// GetFrame
//
template<typename TFrameType>
typename VideoStream<TFrameType>::FramePointer
VideoStream<TFrameType>::GetFrame(SizeValueType frameNumber)
{
// Fetch the frame
typename BufferType::ElementPointer element =
m_DataObjectBuffer->GetBufferContents(frameNumber);
FramePointer frame = dynamic_cast<FrameType*>(element.GetPointer());
return frame;
}
//
// const GetFrame const
//
template<typename TFrameType>
typename VideoStream<TFrameType>::FrameConstPointer
VideoStream<TFrameType>::GetFrame(SizeValueType frameNumber) const
{
typename BufferType::ElementPointer element =
m_DataObjectBuffer->GetBufferContents(frameNumber);
FrameConstPointer frame = dynamic_cast<FrameType*>(element.GetPointer());
return frame;
}
//
// Graft
//
template<typename TFrameType>
void
VideoStream<TFrameType>::Graft(const DataObject* data)
{
// Call TemporalDataObject's Graft implementation
Superclass::Graft(data);
if (data)
{
// Attempt to cast to a VideoStream
const Self* videoData = dynamic_cast< const Self* >(data);
if (!videoData)
{
itkExceptionMacro( << "itk::VideoStream::Graft() cannot cast "
<< typeid( data ).name() << " to "
<< typeid( const Self* ).name() );
}
// Copy the meta data caches
this->SetLargestPossibleSpatialRegionCache(
videoData->GetLargestPossibleSpatialRegionCache());
this->SetRequestedSpatialRegionCache(
videoData->GetRequestedSpatialRegionCache());
this->SetBufferedSpatialRegionCache(
videoData->GetBufferedSpatialRegionCache());
this->SetSpacingCache(videoData->GetSpacingCache());
this->SetOriginCache(videoData->GetOriginCache());
this->SetDirectionCache(videoData->GetDirectionCache());
// Copy the frame buffer
this->SetFrameBuffer(const_cast< BufferType* >(videoData->GetFrameBuffer()));
}
}
//
// SetAllLargestPossibleSpatialRegions
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllLargestPossibleSpatialRegions(typename TFrameType::RegionType region)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameLargestPossibleSpatialRegion(i, region);
}
}
//
// SetAllRequestedSpatialRegions
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllRequestedSpatialRegions(typename TFrameType::RegionType region)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameRequestedSpatialRegion(i, region);
}
}
//
// SetAllBufferedSpatialRegions
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllBufferedSpatialRegions(typename TFrameType::RegionType region)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameBufferedSpatialRegion(i, region);
}
}
//
// SetAllFramesSpacing
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllFramesSpacing(typename TFrameType::SpacingType spacing)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameSpacing(i, spacing);
}
}
//
// SetAllFramesOrigin
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllFramesOrigin(typename TFrameType::PointType origin)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameOrigin(i, origin);
}
}
//
// SetAllFramesDirection
//
template<typename TFrameType>
void
VideoStream<TFrameType>::
SetAllFramesDirection(typename TFrameType::DirectionType direction)
{
SizeValueType numFrames = m_LargestPossibleTemporalRegion.GetFrameDuration();
SizeValueType startFrame = m_LargestPossibleTemporalRegion.GetFrameStart();
// If the largest region is infinite, use the largest of the requested or
// buffered region
if (numFrames == ITK_INFINITE_FRAME_DURATION)
{
SizeValueType bufEnd = m_BufferedTemporalRegion.GetFrameStart() +
m_BufferedTemporalRegion.GetFrameDuration();
SizeValueType reqEnd = m_RequestedTemporalRegion.GetFrameStart() +
m_RequestedTemporalRegion.GetFrameDuration();
(bufEnd > reqEnd) ? (numFrames = bufEnd) : (numFrames = reqEnd);
}
// Go through the number of required frames, making sure none are empty and
// setting the region
for (SizeValueType i = startFrame; i < startFrame + numFrames; ++i)
{
this->SetFrameDirection(i, direction);
}
}
//
// Allocate
//
template<typename TFrameType>
void
VideoStream<TFrameType>::Allocate()
{
SizeValueType numFrames = m_BufferedTemporalRegion.GetFrameDuration();
if (m_DataObjectBuffer->GetNumberOfBuffers() < numFrames)
{
itkExceptionMacro("itk::VideoStream::SetAllLargestPossibleSpatialRegions "
"not enough frame buffers available. Call InitializeEmptyFrames "
"to prepare the frame buffer correctly.");
}
// Go through the number of required frames, making sure none are empty and
// allocating them. We start at 1 and move forwards because frames will be
// added using AppendFrame which first moves the Head forward, then adds the
// frame
for (SizeValueType i = 1; i <= numFrames; ++i)
{
if (!m_DataObjectBuffer->BufferIsFull(i))
{
itkExceptionMacro("itk::VideoStream::SetAllLargestPossibleSpatialRegions "
"empty frame buffer found at offset " << i << ". Call "
"InitializeEmptyFrames to prepare the frame buffer correctly.");
}
FrameType* frame = dynamic_cast<FrameType*>(
m_DataObjectBuffer->GetBufferContents(i).GetPointer());
if (!frame)
{
itkExceptionMacro("itk::VideoStream::SetAllLargestPossibleSpatialRegions "
"could not cast frame " << i << " to the correct type.");
}
frame->Allocate();
}
}
} // end namespace itk
#endif
|