<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.5730.11" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>Dear 
Insight-Users,</FONT><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>I'm using the InsideOrOutside method of the 
vtkOBBTree class to know if a point is inside a surface (polydata). It seems not 
to work in the right way because sometime&nbsp;it returns -1 (internal point) 
even if the point is outside. For this reason, I&nbsp;have the doubt to use 
a&nbsp;not closed surface. Do anybody knows if there is a function to verify if 
the surface I'm using is a closed polydata? It is&nbsp;an isosurface resulting 
from the application of the vtkContourFilter and after&nbsp;extracted using the 
vtkPolyDataConnectivityFilter.</FONT></DIV>
<DIV><FONT face=Arial size=2>Or the problem could be another?</FONT></DIV>
<DIV><FONT face=Arial size=2>Thank you in advance,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Cecilia.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Here is the code I implemented (the part in red is 
were I extract the surface and use the vtkOBBTree class&nbsp;to verify if the 
point is inside the surface itself):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>#include "vtkPolyDataReader.h"<BR>#include 
"vtkPolyDataWriter.h"<BR>#include "vtkAppendPolyData.h"<BR>#include 
"vtkPolyData.h"<BR>#include "vtkOBBTree.h"<BR>#include 
"vtkPolyDataConnectivityFilter.h"<BR>#include "vtkPoints.h"<BR>#include 
"vtkFloatArray.h"<BR>#include "vtkPointData.h"<BR>#include "vtkDataSetWriter.h" 
<BR>#include &lt;vector&gt;<BR>#include &lt;iostream&gt;<BR>#include 
&lt;stdio.h&gt;<BR>#include &lt;math.h&gt;<BR>#include 
&lt;stdlib.h&gt;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>bool isin(std::vector&lt;int&gt; v, int 
a){<BR>&nbsp;for (int w = 0; w &lt; v.size(); w++)<BR>&nbsp;&nbsp;if (v[w] == a) 
return true;<BR>&nbsp;&nbsp;return false;<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><BR><FONT face=Arial size=2>int main( int argc, char * argv[] 
)<BR>{</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;float * point;<BR>&nbsp;FILE 
*file;<BR>&nbsp;vtkPolyDataReader *CentersReader = 
vtkPolyDataReader::New();<BR>&nbsp;vtkPolyDataReader *SurfaceReader = 
vtkPolyDataReader::New();<BR>&nbsp;vtkPoints* outputPoints = 
vtkPoints::New();<BR>&nbsp;vtkPolyData *append_centers = 
vtkPolyData::New();<BR>&nbsp;vtkAppendPolyData *append_surface = 
vtkAppendPolyData::New();<BR>&nbsp;vtkPolyDataConnectivityFilter *connectivity = 
vtkPolyDataConnectivityFilter::New();<BR>&nbsp;vtkOBBTree *OBB = 
vtkOBBTree::New();<BR>&nbsp;vtkPolyData *SavedData = 
vtkPolyData::New();<BR>&nbsp;vtkFloatArray *FA = 
vtkFloatArray::New();<BR>&nbsp;vtkPolyDataWriter *CentersWriter = 
vtkPolyDataWriter::New();<BR>&nbsp;vtkPolyDataWriter *SurfaceWriter = 
vtkPolyDataWriter::New();<BR>&nbsp;vtkDataSetWriter *DataSetWriter = 
vtkDataSetWriter::New();<BR>&nbsp;<BR>&nbsp;if (argc != 
8){<BR>&nbsp;&nbsp;std::cout&lt;&lt;"Use: DeleteCenters.exe initialTimeStep 
finalTimeStep inputCentersPath outputCentersPath inputSurfacePath 
outputSurfacePath outputFilePath";<BR>&nbsp;&nbsp;return 
0;<BR>&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;char temp_a[200];<BR>&nbsp;char 
temp_b[200];<BR>&nbsp;char temp_c[200];<BR>&nbsp;char temp_d[200];<BR>&nbsp;char 
temp_file[200];</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;int initialTimeStep; //initial time step 
<BR>&nbsp;::sscanf(argv[1], "%d", &amp;initialTimeStep);<BR>&nbsp;int 
finalTimeStep; //final time step<BR>&nbsp;::sscanf(argv[2], "%d", 
&amp;finalTimeStep);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;printf 
("**************************************");<BR>&nbsp;for (int m=initialTimeStep; 
m&lt;=finalTimeStep; m++){//cycle in time</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;printf("\n TIME = 
%d\n",m);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;if (m&lt;10) 
{<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_a,"%s/Centers_t0%d.vtk",argv[3], 
m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_b,"%s/TotalIsosurface_t0%d.vtk", 
argv[5],m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_file,"%s/Informations_t0%d.txt", 
argv[7],m);<BR>&nbsp;&nbsp;} else 
{<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_a,"%s/Centers_t%d.vtk",argv[3], 
m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_b,"%s/TotalIsosurface_t%d.vtk", 
argv[5],m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_file,"%s/Informations_t%d.txt", 
argv[7],m);<BR>&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;file=fopen(temp_file,"w");<BR>&nbsp;&nbsp;if 
(file==NULL){perror ("Error in file 
creation.");exit(1);}<BR>&nbsp;&nbsp;fprintf(file, "\n TIME = 
%d\n",m);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;CentersReader-&gt;SetFileName(temp_a);<BR>&nbsp;&nbsp;CentersReader-&gt;Update();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;SurfaceReader-&gt;SetFileName(temp_b);<BR>&nbsp;&nbsp;SurfaceReader-&gt;Update();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;int 
NumPoints=(CentersReader-&gt;GetOutput())-&gt;GetNumberOfPoints();<BR>&nbsp;&nbsp;fprintf(file,"\n 
Number of centers found by the Hough Transform: %d\n",NumPoints);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;<FONT 
color=#ff0000>connectivity-&gt;SetInput(SurfaceReader-&gt;GetOutput());<BR>&nbsp;&nbsp;connectivity-&gt;ScalarConnectivityOn();</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;std::vector&lt;int&gt; 
AddedOrDouble;//lista dei centri e delle membrane già aggiunti o 
doppi<BR>&nbsp;&nbsp;std::vector&lt;int&gt; Cancelled;//vettore dei centri 
cancellati</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;int 
added_centers_counter=0;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;for (int i=0; i&lt;NumPoints; 
i++){//cycle of the connected surfaces (membranes)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;if 
(!isin(AddedOrDouble,i)){</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;float 
range[2];<BR>&nbsp;&nbsp;&nbsp;&nbsp;range[0]=i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;range[1]=i;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
color=#ff0000>connectivity-&gt;SetScalarRange(range);<BR>&nbsp;&nbsp;&nbsp;&nbsp;connectivity-&gt;Update();<BR>&nbsp;&nbsp;&nbsp;&nbsp;connectivity-&gt;Modified();</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;//The class vtkOBBTree 
determine whether a point is inside<BR>&nbsp;&nbsp;&nbsp;&nbsp;//or outside the 
data used to build this OBB tree. The data <BR>&nbsp;&nbsp;&nbsp;&nbsp;//must be 
a closed surface vtkPolyData data set. The return 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;//value is +1 if outside, -1 if inside, and 0 if 
undecided. </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
color=#ff0000>OBB-&gt;SetDataSet(connectivity-&gt;GetOutput());<BR>&nbsp;&nbsp;&nbsp;&nbsp;OBB-&gt;Update();<BR>&nbsp;&nbsp;&nbsp;&nbsp;OBB-&gt;Modified();</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>/*DataSetWriter-&gt;SetInput(OBB-&gt;GetDataSet());<BR>DataSetWriter-&gt;SetFileName("C:/segm_t20_totale/modified/DataSet.vtk");<BR>DataSetWriter-&gt;Update();*/</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;int 
result=0;<BR>//&nbsp;&nbsp;&nbsp;&nbsp;int added_centers_counter=0;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;printf("\n Membrane %d, 
",i);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fprintf(file, "\n Membrane %d, 
",i);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;for (int k=0; 
k&lt;NumPoints; k++){//cycle of the centers found by the Hough 
Transform</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if 
(!isin(AddedOrDouble,k)){</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;point=(CentersReader-&gt;GetOutput())-&gt;GetPoints()-&gt;GetPoint(k);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if 
(k==i){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outputPoints-&gt;InsertPoint 
(added_centers_counter,point[0], point[1], 
point[2]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SavedData-&gt;DeepCopy(connectivity-&gt;GetOutput());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int 
nPoint=SavedData-&gt;GetNumberOfPoints();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FA-&gt;SetNumberOfValues(nPoint);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for 
(float n=0;n&lt;nPoint;n++ 
){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FA-&gt;SetValue(n,added_centers_counter);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SavedData-&gt;GetPointData()-&gt;SetScalars(FA);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;append_surface-&gt;AddInput 
(SavedData);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;added_centers_counter=added_centers_counter+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddedOrDouble.push_back(k);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(file,"internal 
centers: %d",k);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
color=#ff0000>result=OBB-&gt;InsideOrOutside(point);</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (k!=i 
&amp;&amp; 
result==-1){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddedOrDouble.push_back(k);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(file, 
", 
%d",k);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancelled.push_back(k);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;fprintf(file,".\n");</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;if 
(Cancelled.size()&gt;0){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int j=0; 
j&lt;Cancelled.size(); 
j++){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(file, " Center %d, 
cancelled.\n", 
Cancelled[j]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancelled.clear();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;append_centers-&gt;SetPoints(outputPoints);<BR>&nbsp;&nbsp;fprintf(file,"\n 
Number of centers after computation: 
%d\n",append_centers-&gt;GetNumberOfPoints());<BR>&nbsp;&nbsp;fclose(file);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;//Saving<BR>&nbsp;&nbsp;if (m&lt;10) 
{<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_c,"%s/Centers_t0%d.vtk", 
argv[4],m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_d,"%s/TotalIsosurface_t0%d.vtk", 
argv[6],m);<BR>&nbsp;&nbsp;} else 
{<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_c,"%s/Centers_t%d.vtk", 
argv[4],m);<BR>&nbsp;&nbsp;&nbsp;sprintf(temp_d,"%s/TotalIsosurface_t%d.vtk", 
argv[6],m);<BR>&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;CentersWriter-&gt;SetInput(append_centers);<BR>&nbsp;&nbsp;CentersWriter-&gt;SetFileName(temp_c);<BR>&nbsp;&nbsp;CentersWriter-&gt;Update();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;SurfaceWriter-&gt;SetInput(append_surface-&gt;GetOutput());<BR>&nbsp;&nbsp;SurfaceWriter-&gt;SetFileName(temp_d);<BR>&nbsp;&nbsp;SurfaceWriter-&gt;Update();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;printf 
("**************************************");<BR>&nbsp;<BR>&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;return 0;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;if (connectivity) 
connectivity-&gt;Delete();<BR>&nbsp;&nbsp;if (outputPoints) 
outputPoints-&gt;Delete();<BR>&nbsp;&nbsp;if (append_centers) 
append_centers-&gt;Delete();<BR>&nbsp;&nbsp;if (append_surface) 
append_surface-&gt;Delete();<BR>&nbsp;&nbsp;if (CentersReader) 
CentersReader-&gt;Delete();<BR>&nbsp;&nbsp;if (SurfaceReader) 
SurfaceReader-&gt;Delete();<BR>&nbsp;&nbsp;if (CentersWriter) 
CentersWriter-&gt;Delete();<BR>&nbsp;&nbsp;if (SurfaceWriter) 
SurfaceWriter-&gt;Delete();<BR>&nbsp;&nbsp;if (SavedData) 
SavedData-&gt;Delete();<BR>&nbsp;&nbsp;if (FA) 
FA-&gt;Delete();<BR>&nbsp;&nbsp;if (OBB) OBB-&gt;Delete();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;}</FONT></DIV></BODY></HTML>