void mitk::SlicedData::SetGeometry(Geometry3D* aGeometry3D) { if(aGeometry3D!=NULL) { TimeSlicedGeometry::Pointer timeSlicedGeometry = dynamic_cast<TimeSlicedGeometry*>(aGeometry3D); if(timeSlicedGeometry.IsNull()) { SlicedGeometry3D::Pointer slicedGeometry = dynamic_cast<SlicedGeometry3D*>(aGeometry3D); if(slicedGeometry.IsNull()) { Geometry2D* geometry2d = dynamic_cast<Geometry2D*>(aGeometry3D); if(geometry2d!=NULL) { if((GetSlicedGeometry()->GetGeometry2D(0)==geometry2d) && (GetSlicedGeometry()->GetSlices()==1)) return; slicedGeometry = SlicedGeometry3D::New(); slicedGeometry->InitializeEvenlySpaced(geometry2d, 1); } else { slicedGeometry = SlicedGeometry3D::New(); PlaneGeometry::Pointer planeGeometry = PlaneGeometry::New(); planeGeometry->InitializeStandardPlane(aGeometry3D); slicedGeometry->InitializeEvenlySpaced(planeGeometry, (unsigned int)(aGeometry3D->GetExtent(2))); } } assert(slicedGeometry.IsNotNull()); timeSlicedGeometry = TimeSlicedGeometry::New(); timeSlicedGeometry->InitializeEvenlyTimed(slicedGeometry, 1); } Superclass::SetGeometry(timeSlicedGeometry); } else { if(GetGeometry()==NULL) return; Superclass::SetGeometry(NULL); } }
void mitk::BaseData::SetGeometry(Geometry3D* aGeometry3D) { if(aGeometry3D!=NULL) { TimeSlicedGeometry::Pointer timeSlicedGeometry = dynamic_cast<TimeSlicedGeometry*>(aGeometry3D); if ( timeSlicedGeometry.IsNotNull() ) m_TimeSlicedGeometry = timeSlicedGeometry; else { timeSlicedGeometry = TimeSlicedGeometry::New(); m_TimeSlicedGeometry = timeSlicedGeometry; timeSlicedGeometry->InitializeEvenlyTimed(aGeometry3D, 1); } Modified(); } else if( m_TimeSlicedGeometry.IsNotNull() ) { m_TimeSlicedGeometry = NULL; Modified(); } return; }
void mitk::PicFileReader::GenerateOutputInformation() { Image::Pointer output = this->GetOutput(); if ((output->IsInitialized()) && (this->GetMTime() <= m_ReadHeaderTime.GetMTime())) return; itkDebugMacro(<<"Reading file for GenerateOutputInformation()" << m_FileName); // Check to see if we can read the file given the name or prefix // if ( m_FileName == "" && m_FilePrefix == "" ) { throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty"); } if( m_FileName != "") { mitkIpPicDescriptor* header=mitkIpPicGetHeader(const_cast<char *>(m_FileName.c_str()), NULL); if ( !header ) { throw itk::ImageFileReaderException(__FILE__, __LINE__, "File could not be read."); } header=MITKipPicGetTags(const_cast<char *>(m_FileName.c_str()), header); int channels = 1; mitkIpPicTSV_t *tsv; if ( (tsv = mitkIpPicQueryTag( header, "SOURCE HEADER" )) != NULL) { if(tsv->n[0]>1e+06) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( header, "SOURCE HEADER" ); mitkIpPicFreeTag(tsvSH); } } if ( (tsv = mitkIpPicQueryTag( header, "ICON80x80" )) != NULL) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag( header, "ICON80x80" ); mitkIpPicFreeTag(tsvSH); } if ( (tsv = mitkIpPicQueryTag( header, "VELOCITY" )) != NULL) { ++channels; mitkIpPicDelTag( header, "VELOCITY" ); } if( header == NULL || header->bpe == 0) { itk::ImageFileReaderException e(__FILE__, __LINE__); itk::OStringStream msg; msg << " Could not read file " << m_FileName.c_str(); e.SetDescription(msg.str().c_str()); throw e; return; } // First initialize the geometry of the output image by the pic-header SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New(); PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry); // if pic image only 3D, the n[3] value is not initialized unsigned int timesteps = 1; if( header->dim > 3 ) timesteps = header->n[3]; TimeSlicedGeometry::Pointer timeSliceGeometry = TimeSlicedGeometry::New(); timeSliceGeometry->InitializeEvenlyTimed(slicedGeometry, timesteps); timeSliceGeometry->ImageGeometryOn(); // Cast the pic descriptor to ImageDescriptor and initialize the output output->Initialize( CastToImageDescriptor(header)); output->SetGeometry( timeSliceGeometry ); mitkIpPicFree ( header ); } else { int numberOfImages=0; m_StartFileIndex=0; mitkIpPicDescriptor* header=NULL; char fullName[1024]; while(m_StartFileIndex<10) { sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+numberOfImages); FILE * f=fopen(fullName,"r"); if(f==NULL) { //already found an image? if(numberOfImages>0) break; //no? let's increase start ++m_StartFileIndex; } else { fclose(f); //only open the header of the first file found, //@warning what to do when images do not have the same size?? if(header==NULL) { header=mitkIpPicGetHeader(fullName, NULL); header=MITKipPicGetTags(fullName, header); } ++numberOfImages; } } printf("\n numberofimages %d\n",numberOfImages); if(numberOfImages==0) { itk::ImageFileReaderException e(__FILE__, __LINE__); itk::OStringStream msg; msg << "no images found"; e.SetDescription(msg.str().c_str()); throw e; return; } //@FIXME: was ist, wenn die Bilder nicht alle gleich gross sind? if(numberOfImages>1) { printf("\n numberofimages %d > 1\n",numberOfImages); header->dim=3; header->n[2]=numberOfImages; } printf(" \ninitialisize output\n"); output->Initialize( CastToImageDescriptor(header) ); mitkIpPicFree ( header ); } m_ReadHeaderTime.Modified(); }