Orfeo Toolbox  4.0
itkDataObject.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #include "itkProcessObject.h"
37 #if __GNUC__ >= 4
38 #pragma GCC visibility push(default)
39 #endif
41 #if __GNUC__ >= 4
42 #pragma GCC visibility pop
43 #endif
44 
45 // Manual instantiation is necessary to prevent link errors
46 template class ITKCommon_EXPORT itk::SmartPointerForwardReference< itk::ProcessObject >;
47 
48 namespace itk
49 {
50 // after use by filter
51 bool DataObject:: m_GlobalReleaseDataFlag = false;
52 
53 DataObjectError
54 ::DataObjectError():
55  ExceptionObject(), m_DataObject(0)
56 {}
57 
59 ::DataObjectError(const char *file, unsigned int lineNumber):
60  ExceptionObject(file, lineNumber), m_DataObject(0)
61 {}
62 
64 ::DataObjectError(const std::string & file, unsigned int lineNumber):
65  ExceptionObject(file, lineNumber), m_DataObject(0)
66 {}
67 
70  ExceptionObject(orig)
71 {
72  m_DataObject = orig.m_DataObject;
73 }
74 
78 {
80  m_DataObject = orig.m_DataObject;
81  return *this;
82 }
83 
84 void
87 {
88  m_DataObject = dobj;
89 }
90 
91 DataObject *
94 {
95  return m_DataObject;
96 }
97 
98 void
100 ::PrintSelf(std::ostream & os, Indent indent) const
101 {
103 
104  os << indent << "Data object: ";
105  if ( m_DataObject )
106  {
107  os << std::endl;
108  m_DataObject->PrintSelf( os, indent.GetNextIndent() );
109  }
110  else
111  {
112  os << "(None)" << std::endl;
113  }
114 }
115 
119 {}
120 
122 ::InvalidRequestedRegionError(const char *file, unsigned int lineNumber):
123  DataObjectError(file, lineNumber)
124 {}
125 
127 ::InvalidRequestedRegionError(const std::string & file, unsigned int lineNumber):
128  DataObjectError(file, lineNumber)
129 {}
130 
133  DataObjectError(orig)
134 {}
135 
139 {
141  return *this;
142 }
143 
144 void
146 ::PrintSelf(std::ostream & os, Indent indent) const
147 {
148  DataObjectError::PrintSelf(os, indent);
149 }
150 
151 //----------------------------------------------------------------------------
152 DataObject::DataObject():m_UpdateMTime()
153 {
154  m_Source = 0;
155  m_SourceOutputName = "";
156  m_ReleaseDataFlag = false;
157 
158  // We have to assume that if a user is creating the data on their own,
159  // then they will fill it with valid data.
160  m_DataReleased = false;
161 
162  m_PipelineMTime = 0;
163 }
164 
165 //----------------------------------------------------------------------------
168 {}
169 
170 //----------------------------------------------------------------------------
171 void
174 {
175 // We don't modify ourselves because the "ReleaseData" methods depend upon
176 // no modification when initialized.
177 //
178 }
179 
180 //----------------------------------------------------------------------------
181 void
184 {
185  if ( val == m_GlobalReleaseDataFlag )
186  {
187  return;
188  }
189  m_GlobalReleaseDataFlag = val;
190 }
191 
192 //----------------------------------------------------------------------------
193 bool
196 {
197  return m_GlobalReleaseDataFlag;
198 }
199 
200 //----------------------------------------------------------------------------
201 void
204 {
205  this->Initialize();
206  m_DataReleased = true;
207 }
208 
209 //----------------------------------------------------------------------------
210 bool
213 {
214  return ( m_GlobalReleaseDataFlag || m_ReleaseDataFlag );
215 }
216 
217 //----------------------------------------------------------------------------
218 // Set the process object that generates this data object.
219 //
220 void
223 {
224  itkDebugMacro("disconnecting from the pipeline.");
225 
226  // disconnect ourselves from the current process object
227  if ( m_Source )
228  {
229  m_Source->SetOutput(m_SourceOutputName, NULL);
230  }
231 
232  // set our release data flag to off by default (purposely done after
233  // we have disconnected from the pipeline so the new output of the
234  // source can copy our original ReleaseDataFlag)
235  this->ReleaseDataFlagOff();
236 
237  // reset our PipelineMTime (there is now nothing upstream from us)
238  m_PipelineMTime = 0;
239 
240  this->Modified();
241 }
242 
243 bool
246 {
247  if ( m_Source == arg && m_SourceOutputName == name )
248  {
249  itkDebugMacro("disconnecting source " << arg
250  << ", source output name " << name);
251 
252  m_Source = 0;
253  m_SourceOutputName = "";
254  this->Modified();
255  return true;
256  }
257  else
258  {
259  itkDebugMacro("could not disconnect source " << arg
260  << ", source output name " << name);
261  return false;
262  }
263 }
264 
265 bool
268 {
269  if ( m_Source != arg || m_SourceOutputName != name )
270  {
271  itkDebugMacro("connecting source " << arg
272  << ", source output name " << name);
273 
274  m_Source = arg;
275  m_SourceOutputName = name;
276  this->Modified();
277  return true;
278  }
279  else
280  {
281  itkDebugMacro("could not connect source " << arg
282  << ", source output name " << name);
283 
284  return false;
285  }
286 }
287 
288 //----------------------------------------------------------------------------
289 
292 ::GetSource() const
293 {
294  itkDebugMacro( "returning Source address " << m_Source.GetPointer() );
295  return m_Source.GetPointer();
296 }
297 
301 {
302  itkDebugMacro("returning Source name " << m_SourceOutputName);
303  return m_SourceOutputName;
304 }
305 
309 {
310  if( ! m_Source )
311  {
312  return 0;
313  }
314  return m_Source->MakeIndexFromOutputName( m_SourceOutputName );
315 }
316 
317 //----------------------------------------------------------------------------
318 void
320 ::PrintSelf(std::ostream & os, Indent indent) const
321 {
322  Object::PrintSelf(os, indent);
323 
324  if ( m_Source )
325  {
326  os << indent << "Source: (" << m_Source.GetPointer() << ") \n";
327  os << indent << "Source output name: " << m_SourceOutputName << "\n";
328  }
329  else
330  {
331  os << indent << "Source: (none)\n";
332  os << indent << "Source output name: (none)\n";
333  }
334 
335  os << indent << "Release Data: "
336  << ( m_ReleaseDataFlag ? "On\n" : "Off\n" );
337 
338  os << indent << "Data Released: "
339  << ( m_DataReleased ? "True\n" : "False\n" );
340 
341  os << indent << "Global Release Data: "
342  << ( m_GlobalReleaseDataFlag ? "On\n" : "Off\n" );
343 
344  os << indent << "PipelineMTime: " << m_PipelineMTime << std::endl;
345  os << indent << "UpdateMTime: " << m_UpdateMTime << std::endl;
346  os << indent << "RealTimeStamp: " << m_RealTimeStamp << std::endl;
347 }
348 
349 // The following methods are used for updating the data processing pipeline.
350 //
351 
352 //----------------------------------------------------------------------------
353 void
356 {
357  this->UpdateOutputInformation();
358  this->PropagateRequestedRegion();
359  this->UpdateOutputData();
360 }
361 
362 void
365 {
366 
367  if ( this->GetSource() )
368  {
369  this->GetSource()->UpdateOutputInformation();
370  }
371 }
372 
373 void
376 {
377  this->PropagateResetPipeline();
378 }
379 
380 void
383 {
384  if ( m_Source )
385  {
386  m_Source->PropagateResetPipeline();
387  }
388 }
389 
390 //----------------------------------------------------------------------------
391 void
394 {
395  // If we need to update due to PipelineMTime, or the fact that our
396  // data was released, then propagate the update region to the source
397  // if there is one.
398  if ( m_UpdateMTime < m_PipelineMTime || m_DataReleased
399  || this->RequestedRegionIsOutsideOfTheBufferedRegion() )
400  {
401  if ( m_Source )
402  {
403  m_Source->PropagateRequestedRegion(this);
404  }
405  }
406 
407  // Check that the requested region lies within the largest possible region
408  if ( !this->VerifyRequestedRegion() )
409  {
410  // invalid requested region, throw an exception
411  InvalidRequestedRegionError e(__FILE__, __LINE__);
412  e.SetLocation(ITK_LOCATION);
413  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
414  e.SetDataObject(this);
415 
416  throw e;
417  // return;
418  }
419 }
420 
421 //----------------------------------------------------------------------------
422 void
425 {
426  // If we need to update due to PipelineMTime, or the fact that our
427  // data was released, then propagate the UpdateOutputData to the source
428  // if there is one.
429  if ( m_UpdateMTime < m_PipelineMTime || m_DataReleased
430  || this->RequestedRegionIsOutsideOfTheBufferedRegion() )
431  {
432  if ( m_Source )
433  {
434  m_Source->UpdateOutputData(this);
435  }
436  }
437 }
438 
439 //----------------------------------------------------------------------------
440 void
443 {
444  this->m_DataReleased = 0;
445  this->Modified();
446  this->m_UpdateMTime.Modified();
447 }
448 
449 //----------------------------------------------------------------------------
453 {
454  return m_UpdateMTime.GetMTime();
455 }
456 
457 } // end namespace itk

Generated at Sat Mar 8 2014 14:32:08 for Orfeo Toolbox with doxygen 1.8.3.1