# [Insight-users] Normal overlap

Niccolo' Camarlinghi niccolo.camarlinghi at pi.infn.it
Mon Sep 8 06:03:10 EDT 2008

Dear all,

I'm trying to evaluate normals to a surface.
http://www.itk.org/pipermail/insight-users/2008-June/026137.html , but i
was wondering if the extraction of the normals can be implemented using
simplex mesh that has a public method to compute normal at each node.
When i compute one  normal i got segfault in the last line of the
allegated code, someone can tell me if i'm doing a no sense operation?

Many thanks

Niccolo' Camarlinghi

InputImageType::RegionType regione;
InputImageType::SizeType size;
InputImageType::IndexType index;
size[0]=100;
size[1]=100;
size[2]=100;
index[0]=0;
index[1]=0;
index[2]=0;
regione.SetSize(size);
regione.SetIndex(index);
img->SetRegions(regione);
img->Allocate();
InputIteratorType it(img,regione);
//create a sphere for extracting a surface
for (it.GoToBegin();!it.IsAtEnd();++it)
{

InputImageType::IndexType point=it.GetIndex();

if ((point[0]-50)*(point[0]-50)+
(point[1]-50)*(point[1]-50)+(point[2]-50)*(point[2]-50)>100)
{

it.Set(0);

}
else
it.Set(1);

}

typedef itk::DefaultDynamicMeshTraits< float, 3, 3, float, float,
float> MeshTraits;
typedef itk::SimplexMesh<double,3,MeshTraits> SimplexMeshType;
MeshSourceType; // this templated is defined with SimplexMeshType???

MeshSourceType::Pointer meshSource = MeshSourceType::New();
meshSource->SetInput(img);
meshSource->Update();

SimplexMeshType::Pointer simp;
simp=meshSource->GetOutput();

std::cout << "Number of cells"<< std::endl;
std::cout<<simp->GetNumberOfCells()<<std::endl;
std::cout << "Computer normal"<< std::endl;

std::cout << simp->ComputeNormal(1) <<std::endl; // here i got the
segfault , the index in the method is the number of the chosen cell?