[vtkusers] how to calculate normals on the surface of a 3d objectin VTK?
Vidya Raghavan
vidya_raghavan at hotmail.com
Thu Sep 23 16:04:04 EDT 2004
Based on what Bernhard said, I used hedgehog to display normals and also
printed out the individual x, y,z values of every normal. I do get some
negative values, but I'm not too sure if that is right or not.
Does someone know how to use the values of point[0], point[2],point[3[
directly in vtkHedgeHog to view the values? The code I have now is as below:
Thanks!
// Code for calculating surface normals for a given model file.
// First include the required header files for the VTK classes we are using.
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyData.h"
#include "vtkPointData.h"
#include "vtkProperty.h"
#include "vtkHedgeHog.h"
#include "vtkLookUpTable.h"
int main( int argc, char *argv[] )
{
vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New();
reader1->SetFileName("model1.vtp");
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(reader1->GetOutput());
vtkProperty *prop1 = vtkProperty::New();
prop1->SetDiffuseColor(0.5, 0.5, 0.5);
prop1->SetSpecularPower(50);
prop1->SetSpecular(.5);
prop1->SetDiffuse(.8);
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
actor1->SetProperty(prop1);
vtkRenderer *ren= vtkRenderer::New();
ren->AddActor(actor1);
vtkPolyDataNormals *dataset = vtkPolyDataNormals::New();
dataset->SetInput(reader1->GetOutput());
dataset->SetFeatureAngle(60.0);
dataset->FlipNormalsOff();
dataset->Update();
vtkHedgeHog *hhog = vtkHedgeHog::New();
hhog->SetInput(reader1->GetOutput());
hhog->SetScaleFactor(10.3);
hhog->SetVectorModeToUseNormal();
vtkLookupTable *lut = vtkLookupTable::New();
lut->Build();
vtkPolyDataMapper *hhogMapper = vtkPolyDataMapper::New();
hhogMapper->SetInput(hhog->GetOutput());
hhogMapper->SetScalarRange(50, 550);
hhogMapper->SetLookupTable(lut);
hhogMapper->ImmediateModeRenderingOn();
vtkActor *hhogActor = vtkActor::New();
hhogActor->SetMapper(hhogMapper);
ren->AddActor(hhogActor);
//to access the values:
for (int pointID=0; pointID < dataset->GetOutput()->GetNumberOfPoints();
pointID++) {
float *point =
(float*)reader1->GetOutput()->GetPointData()->GetNormals()->GetTuple(pointID);
printf("x -> %f",(float)point[0]);
printf("y -> %f",(float)point[1]);
printf("z -> %f",(float)point[2]);
}
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
renWin->SetSize(800, 800 );
renWin->Render();
reader1->Delete();
dataset->Delete();
actor1->Delete();
prop1->Delete();
ren->Delete();
renWin->Delete();
return 0;
}
>From: "Bernhard Mayrhofer" <berninho1 at hotmail.com>
>To: "Vidya Raghavan" <vidya_raghavan at hotmail.com>,<vtkusers at vtk.org>
>Subject: Re: [vtkusers] how to calculate normals on the surface of a 3d
>objectin VTK?
>Date: Thu, 23 Sep 2004 12:42:10 +0200
>
>Hello Vidya,
>
>every point in the dataset has its own ID. If you want all normals, you
>only need a loop eg:
>for(pointID=0;pointID<dataset->GetOutput()->GetNumberOfPoints();pointID++)
>
>GetPointData()->GetNormals()->GetTuple(pointID) gives you the adress of the
>first coordinate. add 1 to the pointer you get x, add 2 to get the
>z-component.
>
>To display the normals, try vtkHedgeHog. I have never tried it, but i
>image this can help you.
>
>
>Bernhard
>
>---- Original Message ----- From: "Vidya Raghavan"
><vidya_raghavan at hotmail.com>
>To: <berninho1 at hotmail.com>; <vtkusers at vtk.org>
>Sent: Wednesday, September 22, 2004 10:27 PM
>Subject: Re: [vtkusers] how to calculate normals on the surface of a 3d
>objectin VTK?
>
>
>>
>>Bernhard,
>>
>>Thanks so much for your help. Now given I get these float values for the
>>normals, how do I render these values? I would like to verify them by
>>seeing how they are displayed, before I use these values as input for
>>other stuff. Here is the code that I have now: Thanks again.
>>
>>
>>#include "vtkPolyDataMapper.h"
>>#include "vtkRenderWindow.h"
>>#include "vtkCamera.h"
>>#include "vtkActor.h"
>>#include "vtkRenderer.h"
>>#include "vtkXMLPolyDataReader.h"
>>#include "vtkPolyDataNormals.h"
>>#include "vtkPolyData.h"
>>#include "vtkPointData.h"
>>
>>int main( int argc, char *argv[] )
>>{
>>
>>
>>vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New();
>>reader1->SetFileName("model1.vtp");
>>
>>
>>vtkPolyDataNormals *dataset = vtkPolyDataNormals::New();
>>dataset->SetInput(reader1->GetOutput());
>>dataset->SetFeatureAngle(60.0);
>>dataset->FlipNormalsOff();
>>dataset->Update();
>>
>>//to access the values:
>>
>>float *point;
>>int pointID = 1;
>> // do I iterate here, instead of getting the first tuple
>>for the point?
>>
>>point =
>>(float*)reader1->GetOutput()->GetPointData()->GetNormals()->GetTuple(pointID);
>>
>>printf("point -> %f",*point);
>>
>>
>>
>> reader1->Delete();
>> dataset->Delete();
>>
>> //ren1->Delete();
>> //renWin->Delete();
>> return 0;
>>}
>>
>>
>>
>>>From: "Bernhard Mayrhofer" <berninho1 at hotmail.com>
>>>To: "Vidya Raghavan" <vidya_raghavan at hotmail.com>
>>>Subject: Re: [vtkusers] how to calculate normals on the surface of a 3d
>>>objectin VTK?
>>>Date: Wed, 22 Sep 2004 09:16:57 +0200
>>>
>>>
>>>hi vidya,
>>>
>>>the C++ code i used to create normals is:
>>>
>>>vtkPolyDataNormals *dataset = vtkPolyDataNormals::New ();
>>>dataset->SetInput(TrianglesModel->GetOutput());
>>>dataset->SetFeatureAngle(60.0);
>>>dataset->FlipNormalsOff();
>>>dataset->Update();
>>>
>>>to access the values, i used:
>>>float *point;
>>>point=Model->GetOutput()->GetPointData()->GetNormals()->GetTuple(pointID);
>>>
>>>bernhard
>>>
>>>
>>>
>>>
>>>----- Original Message ----- From: "Vidya Raghavan"
>>><vidya_raghavan at hotmail.com>
>>>To: <vtkusers at public.kitware.com>
>>>Sent: Tuesday, September 21, 2004 6:05 PM
>>>Subject: [vtkusers] how to calculate normals on the surface of a 3d
>>>objectin VTK?
>>>
>>>
>>>>Hi,
>>>>
>>>>I currently have code to display 3D segmented data. Is there a way I can
>>>>calulate normals at every point on the surface of the object?
>>>>
>>>>Thanks for any help,
>>>>
>>>>-vidya
>>>>
>>>>_________________________________________________________________
>>>>Search for your life partner made easy.
>>>>http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 On
>>>>BharatMatrimony.com
>>>>
>>>>_______________________________________________
>>>>This is the private VTK discussion list. Please keep messages on-topic.
>>>>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>>>>Follow this link to subscribe/unsubscribe:
>>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>
>>
_________________________________________________________________
The MSN featured offers! Know the power of a tick mark!
http://server1.msn.co.in/features04/general/featuredoffers/index.asp Get
cool discounts and offers!
More information about the vtkusers
mailing list