KWStyle - itkDataObject.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkDataObject.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:34 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 DEF =========================================================================*/
20 #include "itkDataObject.h"
21 #include "itkProcessObject.h"
22 #include "itkObjectFactory.h"
23 #include "itkSmartPointerForwardReference.txx"
24
25 // Manual instantiation is necessary to prevent link errors
26 template class itk::SmartPointerForwardReference<itk::ProcessObject>;
27
28 namespace itk
29 {
30   
31 // after use by filter
32 bool DataObject::m_GlobalReleaseDataFlag = false;
33
34 DataObjectError
35 ::DataObjectError()
36 IND **: ExceptionObject(), m_DataObject(0)
37 {
38 }
39   
40 DataObjectError
41 ::DataObjectError(const char *file, unsigned int lineNumber)
42 IND **: ExceptionObject(file, lineNumber), m_DataObject(0)
43 {
44 }
45
46 DataObjectError
47 ::DataObjectError(const std::string& file, unsigned int lineNumber)
48 IND **: ExceptionObject(file, lineNumber), m_DataObject(0)
49 {
50 }  
51
52 DataObjectError
53 ::DataObjectError(const DataObjectError &orig)
54 IND **: ExceptionObject( orig )
55 {
56   m_DataObject = orig.m_DataObject;
57 }
58
59 DataObjectError&
60 DataObjectError
61 ::operator=( const DataObjectError& orig)
62 {
63   ExceptionObject::operator= (orig);
64   m_DataObject = orig.m_DataObject;
65   return *this;
66 }
67
68 void
69 DataObjectError
70 ::SetDataObject(DataObject *dobj)
71 {
72   m_DataObject = dobj;
73 }
74
75 DataObject*
76 DataObjectError
77 ::GetDataObject()
78 {
79   return m_DataObject;
80 }
81
82
83 void
84 DataObjectError
85 ::PrintSelf(std::ostream& os, Indent indent) const
86 {
87   ExceptionObject::Print( os);
88     
89   os << indent << "Data object: ";
90   if (m_DataObject)
91     {
92     os << std::endl;
93     m_DataObject->PrintSelf(os, indent.GetNextIndent());
94     }
95   else
96     {
97     os << "(None)" << std::endl;
98     }
99 }
100
101
102 InvalidRequestedRegionError
103 ::InvalidRequestedRegionError()
104   : DataObjectError()
105 {
106 }
107
108 InvalidRequestedRegionError
109 ::InvalidRequestedRegionError(const char *file, unsigned int lineNumber)
110   : DataObjectError(file, lineNumber)
111 {
112 }
113
114 InvalidRequestedRegionError
115 ::InvalidRequestedRegionError(const std::string& file, unsigned int lineNumber)
116   : DataObjectError(file, lineNumber)
117 {
118 }  
119
120 InvalidRequestedRegionError
121 ::InvalidRequestedRegionError(const InvalidRequestedRegionError &orig)
122   : DataObjectError( orig )
123 {
124 }
125
126 InvalidRequestedRegionError&
127 InvalidRequestedRegionError
128 ::operator=( const InvalidRequestedRegionError& orig)
129 {
130   DataObjectError::operator= (orig);
131   return *this;
132 }
133
134 void
135 InvalidRequestedRegionError
136 ::PrintSelf(std::ostream& os, Indent indent) const
137 {
138   DataObjectError::PrintSelf( os, indent );
139 }
140
141
142 //----------------------------------------------------------------------------
143 DataObject::
144 DataObject() : m_UpdateMTime()
145 {
146   m_Source = 0;
147   m_SourceOutputIndex = 0;
148   m_ReleaseDataFlag = false;
149
150   // We have to assume that if a user is creating the data on their own,
151   // then they will fill it with valid data.
152   m_DataReleased = false;
153
154   m_PipelineMTime = 0;
155 }
156
157 //----------------------------------------------------------------------------
158 DataObject
159 ::~DataObject()
160 {
161 }
162
163
164 //----------------------------------------------------------------------------
165 void 
166 DataObject
167 ::Initialize()
168 {
169 // We don't modify ourselves because the "ReleaseData" methods depend upon
170 // no modification when initialized.
171 //
172 }
173
174 //----------------------------------------------------------------------------
175 void 
176 DataObject
177 ::SetGlobalReleaseDataFlag(bool val)
178 {
179   if (val == m_GlobalReleaseDataFlag)
180     {
181     return;
182     }
183   m_GlobalReleaseDataFlag = val;
184 }
185
186 //----------------------------------------------------------------------------
187 bool 
188 DataObject
189 ::GetGlobalReleaseDataFlag()
190 {
191   return m_GlobalReleaseDataFlag;
192 }
193
194 //----------------------------------------------------------------------------
195 void 
196 DataObject
197 ::ReleaseData()
198 {
199   this->Initialize();
200   m_DataReleased = true;
201 }
202
203 //----------------------------------------------------------------------------
204 bool 
205 DataObject
206 ::ShouldIReleaseData() const
207 {
208   return ( m_GlobalReleaseDataFlag || m_ReleaseDataFlag );
209 }
210
211 //----------------------------------------------------------------------------
212 // Set the process object that generates this data object.
213 //
214 void 
215 DataObject
216 ::DisconnectPipeline() 
217 {
218   itkDebugMacro( "disconnecting from the pipeline." );
219
220   // disconnect ourselves from the current process object
221   if (m_Source)
222     {
223     m_Source->SetNthOutput(m_SourceOutputIndex, 0);
224     }
225
226   // set our release data flag to off by default (purposely done after
227   // we have disconnected from the pipeline so the new output of the
228   // source can copy our original ReleaseDataFlag)
229   this->ReleaseDataFlagOff();
230
231   // reset our PipelineMTime (there is now nothing upstream from us)
232   m_PipelineMTime = 0;
233
234   this->Modified(); 
235 }
236
237
238 bool
239 DataObject
240 ::DisconnectSource(ProcessObject *arg, unsigned int idx) const
241 {
242   if ( m_Source == arg && m_SourceOutputIndex == idx)
243     {
244     itkDebugMacro( "disconnecting source  " << arg
245                    << ", source output index " << idx);
246
247     m_Source = 0;
248     m_SourceOutputIndex = 0;
249     this->Modified();
250     return true;
251     }
252   else
253     {
254     itkDebugMacro( "could not disconnect source  " << arg
255                    << ", source output index " << idx);
256     return false;
257     }
258 }
259
260 bool
261 DataObject
262 ::ConnectSource(ProcessObject *arg, unsigned int idx) const
263 {
264   if ( m_Source != arg || m_SourceOutputIndex != idx)
265     {
266     itkDebugMacro( "connecting source  " << arg
267                    << ", source output index " << idx);
268
269     m_Source = arg;
270     m_SourceOutputIndex = idx;
271     this->Modified();
272     return true;
273     }
274   else
275     {
276     itkDebugMacro( "could not connect source  " << arg
277                    << ", source output index " << idx);
278
279     return false;
280     }
281 }
282
283
284 //----------------------------------------------------------------------------
285
286 SmartPointerForwardReference<ProcessObject>
287 DataObject
288 ::GetSource() const
289 {
290   itkDebugMacro("returning Source address " << m_Source.GetPointer() );
291   return m_Source.GetPointer();
292 }
293
294 unsigned int
295 DataObject
296 ::GetSourceOutputIndex() const
297 {
298   itkDebugMacro("returning Source index " << m_SourceOutputIndex );
299   return m_SourceOutputIndex;
300 }
301
302
303 //----------------------------------------------------------------------------
304 void 
305 DataObject
306 ::PrintSelf(std::ostream& os, Indent indent) const
307 {
308   Object::PrintSelf(os,indent);
309
310   if ( m_Source )
311     {
312     os << indent << "Source: (" << m_Source.GetPointer() << ") \n";
313     os << indent << "Source output index: " << m_SourceOutputIndex << "\n";
314     }
315   else
316     {
317     os << indent << "Source: (none)\n";
318     os << indent << "Source output index:  0\n";
319     }
320
321   os << indent << "Release Data: " 
322      << (m_ReleaseDataFlag ? "On\n" : "Off\n");
323
324   os << indent << "Data Released: " 
325      << (m_DataReleased ? "True\n" : "False\n");
326   
327   os << indent << "Global Release Data: " 
328      << (m_GlobalReleaseDataFlag ? "On\n" : "Off\n");
329
330   os << indent << "PipelineMTime: " << m_PipelineMTime << std::endl;
331   os << indent << "UpdateMTime: " << m_UpdateMTime << std::endl;
332 }
333
334 // The following methods are used for updating the data processing pipeline.
335 //
336
337 //----------------------------------------------------------------------------
338 void 
339 DataObject
340 ::Update()
341 {
342   this->UpdateOutputInformation();
343   this->PropagateRequestedRegion();
344   this->UpdateOutputData();
345 }
346
347
348 void
349 DataObject
350 ::UpdateOutputInformation()
351 {
352   if (this->GetSource())
353     {
354     this->GetSource()->UpdateOutputInformation();
355     }
356 }
357
358 void
359 DataObject
360 ::ResetPipeline()
361 {
362   this->PropagateResetPipeline();
363 }
364
365 void
366 DataObject
367 ::PropagateResetPipeline()
368 {
369   if (m_Source)
370     {
371     m_Source->PropagateResetPipeline();
372     }
373 }
374
375
376 //----------------------------------------------------------------------------
377 void 
378 DataObject
379 ::PropagateRequestedRegion() throw (InvalidRequestedRegionError)
380 {
381   // If we need to update due to PipelineMTime, or the fact that our
382   // data was released, then propagate the update region to the source 
383   // if there is one.
384   if ( m_UpdateMTime < m_PipelineMTime || m_DataReleased ||
385        this->RequestedRegionIsOutsideOfTheBufferedRegion() )
386     {
387     if ( m_Source )
388       {
389       m_Source->PropagateRequestedRegion(this);
390       }
391     }
392   
393   // Check that the requested region lies within the largest possible region
394   if ( ! this->VerifyRequestedRegion() )
395     {
396     // invalid requested region, throw an exception
397     InvalidRequestedRegionError e(__FILE__, __LINE__);
398     e.SetLocation(ITK_LOCATION);
399 LEN     e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
400     e.SetDataObject(this);
401     
402     throw e;
403     // return;
404     }
405 }
406
407 //----------------------------------------------------------------------------
408 void 
409 DataObject
410 ::UpdateOutputData()
411 {
412   // If we need to update due to PipelineMTime, or the fact that our
413   // data was released, then propagate the UpdateOutputData to the source
414   // if there is one.
415   if ( m_UpdateMTime < m_PipelineMTime || m_DataReleased ||
416        this->RequestedRegionIsOutsideOfTheBufferedRegion() )
417     {
418     if ( m_Source )
419       {
420       m_Source->UpdateOutputData(this);
421       } 
422     } 
423 }
424
425 //----------------------------------------------------------------------------
426 void 
427 DataObject
428 ::DataHasBeenGenerated()
429 {
430   m_DataReleased = 0;
431   this->Modified();
432   m_UpdateMTime.Modified();
433 }
434
435 //----------------------------------------------------------------------------
436 unsigned long 
437 DataObject
438 ::GetUpdateMTime() const
439 {
440   return m_UpdateMTime.GetMTime();
441 }
442
443
444 EML
445 // end namespace itk
446

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:04PM
© Kitware Inc.