[vtkusers] How to get normals??
David Doria
daviddoria+vtk at gmail.com
Wed Nov 11 14:34:44 EST 2009
On Wed, Nov 11, 2009 at 2:12 AM, renlishen <renlishen at gmail.com> wrote:
>
> 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...
> --
Renlishen,
Typically when you post to the mailing list, it is helpful to extract
a very simple example of what you are trying to do (< 20 lines)?
I have written a little example that looks like it may get you closer
to your goals here:
http://www.vtk.org/Wiki/Add/Get_Normals_to/from_a_Polydata
Let us know if you are still having problems.
Thanks,
David
More information about the vtkusers
mailing list