[vtkusers] How to get normals??

renlishen renlishen at gmail.com
Wed Nov 11 02:12:11 EST 2009


I want to generate a personal data
and how can I get the normals?

my code:
	vtkImageData *ImageDataSrc = vtkImageData::New() ;
	vtkMarchingCubes *Iso = vtkMarchingCubes::New() ;

	ImageDataSrc->SetDimensions( 512, 512, 512 ) ;
	ImageDataSrc->SetScalarType( VTK_UNSIGNED_CHAR ) ;

	ImageDataSrc->AllocateScalars() ;

	ImageDataSrc = CreateSphere(ImageDataSrc, 256, 256, 256,  80, 100, 0 ) ;
	Iso->SetInput( ImageDataSrc ) ;
	Iso->SetValue( 0, 100 ) ;

	vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
	skinNormals->SetInput(Iso->GetOutput());
	skinNormals->ComputePointNormalsOn() ;

	vtkPolyData *pData = vtkPolyData::New() ;
	pData->DeepCopy( ( vtkDataSet*)skinNormals->GetOutput() ) ;
	pData->Update() ;
	double *a_pointer ;
	double p_normal[ 3 ] ;
	a_pointer = p_normal ;
	pData->GetPointData()->GetNormals()->GetTuple(1, a_pointer) ; <----Is it
right?

vtkImageData* CVTKMarchingCubeView::CreateSphere(vtkImageData* pTarget, int
CircleCenterX, int CircleCenterY, int CircleCenterZ, int Radius, int
FgValue, int BgValue)
{	
	int SrcDims[3];
	pTarget->GetDimensions(SrcDims);
	if(Radius > SrcDims[0] || Radius > SrcDims[1] )
	{
		return NULL;
	}
	if(CircleCenterX >= SrcDims[0] || CircleCenterY >= SrcDims[1] ||
CircleCenterZ >= SrcDims[2])
	{
		return NULL;
	}

	unsigned char * pTar = (unsigned char *)pTarget->GetScalarPointer();
	int r = Radius*Radius;
	int dx,dy,dz;

	for (int kLoop = 0; kLoop < SrcDims[2]; kLoop++)
	{
		for (int iLoop = 0; iLoop < SrcDims[1]; iLoop++)
		{
			for (int jLoop = 0; jLoop < SrcDims[0]; jLoop++)
			{
				dx = jLoop-CircleCenterX;
				dy = iLoop-CircleCenterY;
				dz = kLoop-CircleCenterZ;
				if(  dx * dx + dy * dy + dz * dz  <= r)
				{
					*pTar = FgValue;
				}
				else
					*pTar = BgValue;

				pTar++;
			}
		}
	}
	return pTarget;

}


How can I get the point's normal on the sphere?
Thanks for your help...
-- 
View this message in context: http://old.nabble.com/How-to-get-normals---tp26297021p26297021.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list