예제 #1
0
vtkImageData* CImageLoader::load( std::string sFilename, TImagePtr& imagePtr )
{
	cerr << "Loading data... ";
	TDataFile theData = getFileServer().loadDataSet( sFilename );
	if ( theData.first->getType() == typeid( short ) )
	{
		imagePtr = static_pointer_cast<TImage>( theData.first );
		cerr << "Correct" << endl;
	}
	else
		cerr << theData.first->getType().name() << endl;
	cerr << "done" << endl;
	cerr << "Starting conversion... ";
	// Create vtk structured points structure
  vtkImageData* sp = vtkImageData::New();
  sp->SetDimensions( theData.first->getExtent(0), theData.first->getExtent(1), theData.first->getExtent(2) );
  sp->AllocateScalars();	
  // Assign dataset to structured points
  vtkPointData *p=sp->GetPointData();
	vtkShortArray* sArray = NULL;
	vtkDoubleArray* fArray = NULL;
	TField* floatSet = dynamic_cast<TField*>( theData.first.get() );	
	if ( floatSet != NULL )
	{
		fArray = vtkDoubleArray::New();
		fArray->SetArray(floatSet->getArray(),
			theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2), 1 );
		p->SetScalars( fArray );
		sp->SetScalarTypeToDouble();
	}
	else 
	{
		TImage* shortSet = dynamic_cast<TImage*>( theData.first.get() );
		if ( shortSet != NULL )
		{
			short* sA = new short[theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2)];
			short* sAs = sA;
			for( TImage::iterator it = shortSet->begin(); it != shortSet->end(); ++it, ++sAs )
				*sAs = *it;
			sArray = vtkShortArray::New();
			sArray->SetArray( sA,
				theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2), 1 );
			p->SetScalars( sArray );
			sp->SetScalarTypeToShort();
		}		
		else
		{
	    sp->Delete();		
			throw( FileException( "CVTkHandler - Unknown image format in dataset. Image was not saved" ) );
		}
	}
	sp->UpdateData();
	sp->SetSpacing( 1.0, 1.0, 1.0 );
	sp->SetOrigin( static_cast<double>( theData.first->getExtent(0) )/ 2.0, 
		static_cast<double>( theData.first->getExtent(1) )/ 2.0,
		static_cast<double>( theData.first->getExtent(2) )/ 2.0	);
	cerr << sp->GetNumberOfScalarComponents() << endl;
	cerr << "done" << endl;	
	return sp;
}
예제 #2
0
void CExtractRegion::updateMask( TImage& mask, TImage& work, uint index )
{
	TImage::iterator in = work.begin();
	TImage::iterator out = mask.begin();
	while( in != work.end() )
	{
		if ( (*in) > 0 ) (*out) = index;
		++in; ++out;
	}
}
예제 #3
0
ulong CExtractRegion::computeSize( TImage& region )
{
	ulong size = 0;
	TImage::iterator in = region.begin();
	while( in != region.end() )
	{
		if ( (*in) > 0 ) size++;
		++in;
	}	
	return size;
}