Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkImageSource.h"
00020
00021 mitk::ImageSource::ImageSource()
00022 {
00023
00024
00025 OutputImageType::Pointer output
00026 = static_cast<OutputImageType*>(this->MakeOutput(0).GetPointer());
00027 Superclass::SetNumberOfRequiredOutputs(1);
00028 Superclass::SetNthOutput(0, output.GetPointer());
00029 }
00030
00034 mitk::ImageSource::DataObjectPointer mitk::ImageSource::MakeOutput(unsigned int)
00035 {
00036 return static_cast<itk::DataObject*>(OutputImageType::New().GetPointer());
00037 }
00038
00042 mitk::ImageSource::OutputImageType* mitk::ImageSource::GetOutput()
00043 {
00044 if (this->GetNumberOfOutputs() < 1)
00045 {
00046 return 0;
00047 }
00048
00049 return static_cast<OutputImageType*>
00050 (this->BaseProcess::GetOutput(0));
00051 }
00052
00053
00057 mitk::ImageSource::OutputImageType* mitk::ImageSource::GetOutput(unsigned int idx)
00058 {
00059 return static_cast<OutputImageType*>
00060 (this->ProcessObject::GetOutput(idx));
00061 }
00062
00063
00067 void mitk::ImageSource::SetOutput(OutputImageType *output)
00068 {
00069 itkWarningMacro(<< "SetOutput(): This method is slated to be removed from ITK. Please use GraftOutput() in possible combination with DisconnectPipeline() instead." );
00070 BaseProcess::SetNthOutput(0, output);
00071 }
00072
00073
00077 void mitk::ImageSource::GraftOutput(OutputImageType *graft)
00078 {
00079 this->GraftNthOutput(0, graft);
00080 }
00081
00082
00086 void mitk::ImageSource::GraftNthOutput(unsigned int idx, OutputImageType* graft)
00087 {
00088 itkWarningMacro(<< "GraftNthOutput(): This method is not yet implemented for mitk. Implement it before using!!" );
00089 assert(false);
00090 if (idx < this->GetNumberOfOutputs())
00091 {
00092 OutputImageType * output = this->GetOutput(idx);
00093
00094 if (output && graft)
00095 {
00096
00097
00098
00099
00100 output->SetRequestedRegion( graft );
00101
00102
00103
00104
00105 output->CopyInformation( graft );
00106 }
00107 }
00108 }
00109
00110
00111 int mitk::ImageSource::SplitRequestedRegion(int i, int num, OutputImageRegionType& splitRegion)
00112 {
00113
00114 OutputImageType * outputPtr = this->GetOutput();
00115 const SlicedData::SizeType& requestedRegionSize
00116 = outputPtr->GetRequestedRegion().GetSize();
00117
00118 int splitAxis;
00119 SlicedData::IndexType splitIndex;
00120 SlicedData::SizeType splitSize;
00121
00122
00123 splitRegion = outputPtr->GetRequestedRegion();
00124 splitIndex = splitRegion.GetIndex();
00125 splitSize = splitRegion.GetSize();
00126
00127
00128 splitAxis = outputPtr->GetDimension() - 1;
00129 while (requestedRegionSize[splitAxis] == 1)
00130 {
00131 --splitAxis;
00132 if (splitAxis < 0)
00133 {
00134 itkDebugMacro(" Cannot Split");
00135 return 1;
00136 }
00137 }
00138
00139
00140 SlicedData::SizeType::SizeValueType range = requestedRegionSize[splitAxis];
00141 int valuesPerThread = (int)ceil(range/(double)num);
00142 int maxThreadIdUsed = (int)ceil(range/(double)valuesPerThread) - 1;
00143
00144
00145 if (i < maxThreadIdUsed)
00146 {
00147 splitIndex[splitAxis] += i*valuesPerThread;
00148 splitSize[splitAxis] = valuesPerThread;
00149 }
00150 if (i == maxThreadIdUsed)
00151 {
00152 splitIndex[splitAxis] += i*valuesPerThread;
00153
00154 splitSize[splitAxis] = splitSize[splitAxis] - i*valuesPerThread;
00155 }
00156
00157
00158 splitRegion.SetIndex( splitIndex );
00159 splitRegion.SetSize( splitSize );
00160
00161 itkDebugMacro(" Split Piece: " << splitRegion );
00162
00163 return maxThreadIdUsed + 1;
00164 }
00165
00166
00167
00168 void mitk::ImageSource::AllocateOutputs()
00169 {
00170 OutputImagePointer outputPtr;
00171
00172
00173 for (unsigned int i=0; i < this->GetNumberOfOutputs(); i++)
00174 {
00175 outputPtr = this->GetOutput(i);
00176
00177
00178 }
00179 }
00180
00181
00182
00183 void mitk::ImageSource::GenerateData()
00184 {
00185
00186
00187 this->AllocateOutputs();
00188
00189
00190
00191
00192 this->BeforeThreadedGenerateData();
00193
00194
00195 ThreadStruct str;
00196 str.Filter = this;
00197
00198 this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads());
00199 this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str);
00200
00201
00202 this->GetMultiThreader()->SingleMethodExecute();
00203
00204
00205
00206 this->AfterThreadedGenerateData();
00207 }
00208
00209
00210
00211
00212
00213 void mitk::ImageSource::ThreadedGenerateData(const OutputImageRegionType&, int)
00214 {
00215 itkExceptionMacro("subclass should override this method!!!");
00216 }
00217
00218
00219
00220
00221
00222 ITK_THREAD_RETURN_TYPE mitk::ImageSource::ThreaderCallback( void *arg )
00223 {
00224 ThreadStruct *str;
00225 int total, threadId, threadCount;
00226
00227 threadId = ((itk::MultiThreader::ThreadInfoStruct *)(arg))->ThreadID;
00228 threadCount = ((itk::MultiThreader::ThreadInfoStruct *)(arg))->NumberOfThreads;
00229
00230 str = (ThreadStruct *)(((itk::MultiThreader::ThreadInfoStruct *)(arg))->UserData);
00231
00232
00233
00234 SlicedData::RegionType splitRegion;
00235 total = str->Filter->SplitRequestedRegion(threadId, threadCount,
00236 splitRegion);
00237
00238 if (threadId < total)
00239 {
00240 str->Filter->ThreadedGenerateData(splitRegion, threadId);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 return ITK_THREAD_RETURN_VALUE;
00250 }
00251
00252 void mitk::ImageSource::PrepareOutputs()
00253 {
00254 Superclass::PrepareOutputs();
00255 }
00256
00257 void* mitk::ImageSource::GetData()
00258 {
00259 Update();
00260 return GetOutput()->GetData();
00261 }
00262
00263 mitkIpPicDescriptor* mitk::ImageSource::GetPic()
00264 {
00265 Update();
00266 return GetOutput()->GetPic();
00267 }
00268
00269 vtkImageData* mitk::ImageSource::GetVtkImageData()
00270 {
00271 Update();
00272 return GetOutput()->GetVtkImageData();
00273 }