This file is indexed.

/usr/include/ITK-4.9/itkVideoFileWriter.hxx is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.

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
/*=========================================================================
 *
 *  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 itkVideoFileWriter_hxx
#define itkVideoFileWriter_hxx

#include "itkVideoFileWriter.h"

#include "itkNumericTraits.h"
#include "itkTemporalDataObject.h"
#include "itkMath.h"

namespace itk
{

//-CONSTRUCTOR DESTRUCTOR PRINT------------------------------------------------

//
// Constructor
//
template< typename TInputVideoStream >
VideoFileWriter< TInputVideoStream >
::VideoFileWriter() :
  m_FileName(""),
  m_VideoIO(ITK_NULLPTR),
  m_FramesPerSecond(24),
  m_FourCC("MP42"),
  m_NumberOfComponents(0)
{
  // TemporalProcessObject inherited members
  this->TemporalProcessObject::m_UnitInputNumberOfFrames = 1;
  this->TemporalProcessObject::m_UnitOutputNumberOfFrames = 1;
  this->TemporalProcessObject::m_FrameSkipPerOutput = 1;
  this->TemporalProcessObject::m_InputStencilCurrentFrameIndex = 0;
}


//
// Destructor
//
template< typename TInputVideoStream >
VideoFileWriter< TInputVideoStream >
::~VideoFileWriter()
{
  this->FinishWriting();
}


//
// PrintSelf
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::PrintSelf(std::ostream &os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);

  os << indent << "FileName: " << m_FileName << std::endl;
  if (!m_VideoIO.IsNull())
    {
    os << indent << "VideoIO:" << std::endl;
    m_VideoIO->Print(os, indent.GetNextIndent());
    }
}

//-PUBLIC METHODS--------------------------------------------------------------

//
// SetInput
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::SetInput( const VideoStreamType* input )
{
  this->ProcessObject::SetNthInput(0, const_cast<VideoStreamType*>(input));
}

//
// GetInput
//
template< typename TInputVideoStream >
const typename VideoFileWriter< TInputVideoStream >::VideoStreamType*
VideoFileWriter< TInputVideoStream >
::GetInput()
{
  if (this->GetNumberOfInputs() < 1)
    {
    return ITK_NULLPTR;
    }

  return static_cast<VideoStreamType*>(this->ProcessObject::GetInput(0));
}


//
// SetVideoIO
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::SetVideoIO(IOBasePointer videoIO)
{
  m_VideoIO = videoIO;
}


//
// Write
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::Write()
{
  //
  // Make sure everything is set correctly
  //

  // Make sure input is available
  const VideoStreamType* input = this->GetInput();
  if (input == ITK_NULLPTR)
    {
    itkExceptionMacro("No input to writer");
    }

  // Make sure FileName is specified
  if (m_FileName == "")
    {
    itkExceptionMacro("No FileName set for writer");
    }

  // Make sure FramesPerSecond and FourCC have been set
  if (Math::ExactlyEquals(m_FramesPerSecond, NumericTraits< TemporalRatioType >::ZeroValue()) || m_FourCC.length() == 0)
    {
    itkExceptionMacro("Cannot write with FramesPerSecond or FourCC unset");
    }


  //
  // Trigger the first phase of the pipeline. We don't need to propagate the
  // requested region because that will get redone during the data generation
  // phase using temporal streaming.
  //

  // Update the output information upstream
  VideoStreamType* nonConstInput = const_cast<VideoStreamType*>(this->GetInput());
  nonConstInput->UpdateOutputInformation();


  //
  // Set up the writer using information propagated from upstream
  //

  // Initialize writing information
  if (!this->InitializeOutputParameters())
    {
    itkExceptionMacro("Could not initialize output parameters for writing");
    }

  // Initialize VideoIO if necessary
  if (m_VideoIO.IsNull() && !this->InitializeVideoIO())
    {
    itkExceptionMacro("Could not create VideoIO");
    }

  // Set output information
  m_VideoIO->SetWriterParameters( m_FramesPerSecond,
                                  m_Dimensions,
                                  m_FourCC.c_str(),
                                  m_NumberOfComponents,
                                  m_ComponentType );
  m_VideoIO->SetFileName(m_FileName);

  // If no OutputTemporalRegion specified, get the largest one possible and
  // use that.
  if (m_OutputTemporalRegion.GetFrameDuration() == 0)
    {
    m_OutputTemporalRegion = input->GetLargestPossibleTemporalRegion();
    }

  // FIXME: For now we will always request the entire spatial region of each
  // frame as output
  SizeValueType frameStart = m_OutputTemporalRegion.GetFrameStart();
  SizeValueType numFrames = m_OutputTemporalRegion.GetFrameDuration();
  for (SizeValueType i = frameStart; i < frameStart + numFrames; ++i)
    {
    nonConstInput->SetFrameRequestedSpatialRegion(i,
      input->GetFrameLargestPossibleSpatialRegion(i));
    }

  // Propagate the requested regions
  nonConstInput->PropagateRequestedRegion();

  // Set the output's temporal regions to match the input's. The output object
  // doesn't actually get used, but its temporal regions are used by the
  // temporal streaming in TemporalProcessObject's GenerateData. We set the
  // buffered region to an empty region so that the entire requested region is
  // unbuffered and gets written.
  TemporalDataObject::Pointer output = TemporalDataObject::New();
  output->SetLargestPossibleTemporalRegion(m_OutputTemporalRegion);
  output->SetRequestedTemporalRegion(m_OutputTemporalRegion);
  output->SetBufferedTemporalRegion(TemporalRegion());
  this->ProcessObject::SetNthOutput(0, output);


  //
  // Trigger the data generation phase of the pipeline
  //

  // Notify observers
  this->InvokeEvent( StartEvent() );

  // Write the data
  this->GenerateData();

  // Notify observers
  this->InvokeEvent( EndEvent() );

  // Finish writing the file
  this->FinishWriting();
}


//
// FinishWriting
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::FinishWriting()
{
  if (!m_VideoIO.IsNull())
    {
    m_VideoIO->FinishReadingOrWriting();
    }
}

//
// Update
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::Update()
{
  this->Write();
}

//
// UpdateLargestPossibleRegion
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::UpdateLargestPossibleRegion()
{
  const VideoStreamType* input = this->GetInput();
  if (input == ITK_NULLPTR)
    {
    itkExceptionMacro("No input to writer");
    }
  m_OutputTemporalRegion = input->GetLargestPossibleTemporalRegion();
  this->Write();
}


//-PROTECTED METHODS-----------------------------------------------------------

//
// TemporalStreamingGenerateData
//
template< typename TInputVideoStream >
void
VideoFileWriter< TInputVideoStream >
::TemporalStreamingGenerateData()
{
  // Get a non-const pointer to the input and output
  const VideoStreamType* input = dynamic_cast<const VideoStreamType*>(this->GetInput());
  TemporalDataObject* output = dynamic_cast<TemporalDataObject*>(this->GetOutput(0));
  if (!output)
    {
    itkExceptionMacro("Could not cast output to TemporalDataObject");
    }

  // Get the frame we're going to write
  SizeValueType frameNum = output->GetRequestedTemporalRegion().GetFrameStart();
  const FrameType* frame = input->GetFrame(frameNum);
  if (!frame)
    {
    itkExceptionMacro("Could not get input frame " << frameNum << " for writing");
    }

  // Write the frame out
  m_VideoIO->Write(static_cast<const void*>(frame->GetBufferPointer()));
}

//
// InitializeOutputParameters
//
template< typename TInputVideoStream >
bool
VideoFileWriter< TInputVideoStream >
::InitializeOutputParameters()
{
  // InputImage and VideoIO must be valid
  if (this->GetInput() == ITK_NULLPTR)
    {
    return false;
    }

  // Get the frame number for the current frame
  SizeValueType frameNum = this->GetInput()->GetRequestedTemporalRegion().GetFrameStart();

  // Get a non-const pointer so we can get spatial regions (VideoStream isn't const correct)
  const VideoStreamType* input = this->GetInput();

  // Set dimensions
  m_Dimensions.empty();
  typename FrameType::SizeType size =
    input->GetFrameLargestPossibleSpatialRegion(frameNum).GetSize();
  for (unsigned int i = 0; i < FrameType::ImageDimension; ++i)
    {
    m_Dimensions.push_back(size[i]);
    }

  // Set NumberOfComponents. At this point, just handle RGB and RGBA
  // non-scalar pixels
  m_NumberOfComponents =
    itk::NumericTraits<PixelType>::MeasurementVectorType::Length;

  return true;
}


//
// InitializeVideoIO
//
template< typename TInputVideoStream >
bool
VideoFileWriter< TInputVideoStream >
::InitializeVideoIO()
{
  if (m_FileName.length() != 0)
    {
    m_VideoIO = itk::VideoIOFactory::CreateVideoIO(
                             itk::VideoIOFactory::WriteMode, m_FileName.c_str());

    // Return true if a VideoIO was successfully created
    if (!m_VideoIO.IsNull())
      {
      // Get the pixel type
      m_ComponentType = m_VideoIO->GetComponentType();

      return true;
      }
    else
      {
      return false;
      }
    }
  else
    {
    return false;
    }
}

} // end namespace itk

#endif