[ create a new paste ] login | about

Link: http://codepad.org/TOOpENlx    [ raw code | fork ]

C++, pasted on Feb 17:
void ClipVolumeData ( vtkImageData *result, vtkImageData *data, vtkDataSet *element)
{
	vtkImplicitDataSet *ids 			 = vtkImplicitDataSet::New();
	vtkImageReslice *reslice 			 = vtkImageReslice::New();
	vtkImplicitFunctionToImageStencil *stencilCreator = vtkImplicitFunctionToImageStencil::New();
	vtkImageStencil *stencil			 = vtkImageStencil::New();
	double spacing[3], origin[3], bounds[6], center[3];
	int    newbox[6], extent[6];
	




	//compute the new bounding box
	element->ComputeBounds();
	element->GetBounds(bounds);
	element->GetCenter(center);
	data->GetOrigin();
	data->GetSpacing(spacing);										       
	data->GetWholeExtent(extent);



	newbox[0]=(int)((bounds[0]-origin[0])/spacing[0]+.5)+extent[0]-5;
	newbox[1]=(int)((bounds[1]-origin[0])/spacing[0]+.5)+extent[0]+5;
	newbox[2]=(int)((bounds[2]-origin[1])/spacing[1]+.5)+extent[2]-5;
	newbox[3]=(int)((bounds[3]-origin[1])/spacing[1]+.5)+extent[2]+5;
	newbox[4]=(int)((bounds[4]-origin[2])/spacing[2]+.5)+extent[4]-5;
	newbox[5]=(int)((bounds[5]-origin[2])/spacing[2]+.5)+extent[4]+5;
	
        //Transform the world coordinates of the finite element
	double morigin[6], dspacing[3];

	for(int i = 0; i<6; ++i)
	{
		morigin[i] = -origin[i];
	}

	for(int i = 0; i<3; ++i)
	{
		dspacing[i] = 1./spacing[i];
	}

	vtkTransform *translateOrigin = vtkTransform::New();
	translateOrigin->Translate(morigin);
	vtkTransform *scaleSpacing = vtkTransform::New();
	scaleSpacing->Scale(dspacing);
	vtkTransform *translateExtent = vtkTransform::New();
	scaleSpacing->SetInput(translateOrigin);
	translateExtent->SetInput(scaleSpacing);

	ids->SetDataSet(element);
	ids->SetOutValue(-10000);
	ids->SetTransform(translateExtent);
	stencilCreator->SetInput(ids);


	double stencilCreator_Threshold = 0.0;
	stencilCreator->SetThreshold(stencilCreator_Threshold);
	stencilCreator->SetInformationInput(data);



	//Clip the data

	reslice->SetInputConnection(0,data->GetProducerPort());
	reslice->Update();


	double reslice_background_level = 2.;
	reslice->SetBackgroundLevel(reslice_background_level);
	reslice->SetOutputSpacing(spacing);
	reslice->SetOutputOrigin(origin);
	reslice->SetOutputExtent(newbox);
	
	reslice->TransformInputSamplingOff();


	reslice->SetStencil(stencilCreator->GetOutput());
	reslice->Update();



	result->DeepCopy(reslice->GetOutput());

}


Create a new paste based on this one


Comments: