<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
<div>This is my code. Basically I have a mesh "geometry" and I project rays in order to fill the matrix of points.&nbsp;</div><div><br></div><div>***********************************</div><div><div>vtkStructuredPoints *object = prepareVTKObjectForMarching(geom,40);</div><div><br></div><div>//Iso-surface using marching cubes</div><div>vtkMarchingCubes* iso = vtkMarchingCubes::New();</div><div>iso-&gt;SetInput(object);</div><div>iso-&gt;SetValue(0,1); // Surface #0, iso-value=1<span class="Apple-tab-span" style="white-space:pre">                </span></div><div>iso-&gt;Update();</div><div><br></div><div>then the function&nbsp;prepareVTKObjectForMarching</div><div><br></div><div><div>vtkStructuredPoints* prepareVTKObjectForMarching(osg::Geometry *geometry, int steps, string name)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>TBBox bbox = createBoundingBox(geometry);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bbox.length[0] *= 1.2;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bbox.length[1] *= 1.2;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bbox.length[2] *= 1.2;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>float lengthStep = bbox.length[bbox.maxLAxis]/(float)steps;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int dim[3];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>dim[0] = steps;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>dim[1] = steps;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>dim[2] = steps;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double ar[3];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ar[0] = lengthStep;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ar[1] = lengthStep;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ar[2] = lengthStep;</div><div>&nbsp;&nbsp; &nbsp;double origin[3];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>origin[0] = bbox.origin[0];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>origin[1] = bbox.origin[1];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>origin[2] = bbox.origin[2];</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkStructuredPoints *strcP = vtkStructuredPoints::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Set data dimensions, spacing and origin</div><div>&nbsp;&nbsp; &nbsp;strcP-&gt;SetDimensions(dim);&nbsp;</div><div>&nbsp;&nbsp; &nbsp;strcP-&gt;SetSpacing(ar);</div><div>&nbsp;&nbsp; &nbsp;strcP-&gt;SetOrigin(origin);&nbsp;</div><div><br></div><div>&nbsp;&nbsp; &nbsp;vtkDataSet *ds = strcP ;</div><div><br></div><div>&nbsp;&nbsp; &nbsp;vtkDataSetAttributes *a = ds-&gt;GetPointData() ;</div><div><br></div><div>&nbsp;&nbsp; &nbsp;// Data may be vtkUnsignedCharArray or vtkUnsignedShortArray</div><div>&nbsp;&nbsp; &nbsp;vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned int cnt = 0;</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>float zInit = origin[2];</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for(int x = 0; x &lt; steps; x++)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>float xf = bbox.origin[0] + x*lengthStep;<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for(int y = 0; y &lt; steps; y++)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>float yf = bbox.origin[1] + y*lengthStep;<span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>vector&lt;float&gt; listT = getIntersectionPoints(xf,yf,zInit,geometry);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>if(listT.size() == 2)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zIn = zInit + listT.at(0);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zOut = zInit + listT.at(1);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>bool particleAdded = false;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>for(int z = 0; z &lt; steps; z++)</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>float zf = origin[2] + z*lengthStep;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>if(zf &gt;= zIn &amp;&amp; zf &lt;= zOut)</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>scalars-&gt;InsertValue(cnt, 128) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>particleAdded = true;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>else if(zf &lt; zIn)scalars-&gt;InsertValue(cnt, 0) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>else if(zf &gt; zOut &amp;&amp; particleAdded == false)</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>scalars-&gt;InsertValue(cnt,128);</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>particleAdded = true;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>else scalars-&gt;InsertValue(cnt, 0) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>cnt++;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>else if(listT.size() == 4)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zIn1 = zInit + listT.at(0);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zOut1 = zInit + listT.at(1);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zIn2 = zInit + listT.at(2);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>float zOut2 = zInit + listT.at(3);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>for(int z = 0; z &lt; steps; z++)</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>float zf = origin[2] + z*lengthStep;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>if((z &gt;= zIn1 &amp;&amp; z &lt;= zOut1) || (z &gt;= zIn2 &amp;&amp; z &lt;= zOut2))</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>scalars-&gt;InsertValue(cnt, 128);</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>else scalars-&gt;InsertValue(cnt, 0) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>cnt++;<span class="Apple-tab-span" style="white-space:pre">                                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}<span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>else</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{<span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>for(int z = 0; z &lt; steps; z++)</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>scalars-&gt;InsertValue(cnt, 0) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>cnt++;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>a-&gt;SetScalars(scalars) ;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return strcP;</div><div>}</div></div></div><div><br></div><br><br>&gt; Date: Wed, 11 Nov 2009 10:33:06 -0500<br>&gt; Subject: Re: [vtkusers] duplicated vertex in marching cubes?<br>&gt; From: bill.lorensen@gmail.com<br>&gt; To: dev_crisalix@hotmail.com<br>&gt; CC: vtkusers@vtk.org<br>&gt; <br>&gt; Please provide a small, complete example. MC should not generate<br>&gt; duplicate points or vertices. What is the datatype of your scalars?<br>&gt; <br>&gt; On Wed, Nov 11, 2009 at 10:20 AM, lucas Grijander<br>&gt; &lt;dev_crisalix@hotmail.com&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; Hi all!<br>&gt; &gt; I am using vtkMarchingCubes to calculate a 3D mesh of a volume I have. Fist<br>&gt; &gt; I initialize the filter with:<br>&gt; &gt; vtkMarchingCubes* iso = vtkMarchingCubes::New();<br>&gt; &gt; iso-&gt;SetInput(object);<br>&gt; &gt; iso-&gt;SetValue(0,1); // Surface #0, iso-value=1<br>&gt; &gt; iso-&gt;Update();<br>&gt; &gt; then I fill the vtkStructuredPoints.<br>&gt; &gt; The problem I have is, as you can see in the pictures, when you have a close<br>&gt; &gt; look to the trianbles (screen2) you can see duplicated triangles and vertex,<br>&gt; &gt; and this is a huge problem for my application... I supposed vtkMarchingCubes<br>&gt; &gt; should generate a single surface mesh... I don't know if that's the reason,<br>&gt; &gt; but when I fill the vtkStructuredPoints I use<br>&gt; &gt; scalars-&gt;InsertValue(cnt, 0) ; and&nbsp;scalars-&gt;InsertValue(cnt, 128) ;<br>&gt; &gt; I took all these from an example, I still don't know what you have to set as<br>&gt; &gt; values, either 1 or 128... in addition the result change with this number<br>&gt; &gt; and I'm not sure why.<br>&gt; &gt; What should I use as values? and also why I have this "double" triangles<br>&gt; &gt; mesh?<br>&gt; &gt; thanks!<br>&gt; &gt; Jaime.<br>&gt; &gt; ________________________________<br>&gt; &gt; Windows Live: Make it easier for your friends to see what you’re up to on<br>&gt; &gt; Facebook.<br>&gt; &gt; ________________________________<br>&gt; &gt; Keep your friends updated— even when you’re not signed in.<br>&gt; &gt; ________________________________<br>&gt; &gt; Windows Live: Friends get your Flickr, Yelp, and Digg updates when they<br>&gt; &gt; e-mail you.<br>&gt; &gt; _______________________________________________<br>&gt; &gt; Powered by www.kitware.com<br>&gt; &gt;<br>&gt; &gt; Visit other Kitware open-source projects at<br>&gt; &gt; http://www.kitware.com/opensource/opensource.html<br>&gt; &gt;<br>&gt; &gt; Please keep messages on-topic and check the VTK FAQ at:<br>&gt; &gt; http://www.vtk.org/Wiki/VTK_FAQ<br>&gt; &gt;<br>&gt; &gt; Follow this link to subscribe/unsubscribe:<br>&gt; &gt; http://www.vtk.org/mailman/listinfo/vtkusers<br>&gt; &gt;<br>&gt; &gt;<br>                                               <br /><hr />Windows Live: Keep your friends up to date <a href='http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010' target='_new'>with what you do online.</a></body>
</html>