<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. </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->SetInput(object);</div><div>iso->SetValue(0,1); // Surface #0, iso-value=1<span class="Apple-tab-span" style="white-space:pre">                </span></div><div>iso->Update();</div><div><br></div><div>then the function 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> 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> strcP->SetDimensions(dim); </div><div> strcP->SetSpacing(ar);</div><div> strcP->SetOrigin(origin); </div><div><br></div><div> vtkDataSet *ds = strcP ;</div><div><br></div><div> vtkDataSetAttributes *a = ds->GetPointData() ;</div><div><br></div><div> // Data may be vtkUnsignedCharArray or vtkUnsignedShortArray</div><div> 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 < 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 < 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<float> 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 < 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 >= zIn && zf <= 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->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 < zIn)scalars->InsertValue(cnt, 0) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>else if(zf > zOut && 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->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->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 < 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 >= zIn1 && z <= zOut1) || (z >= zIn2 && z <= 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->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->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 < 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->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->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>> Date: Wed, 11 Nov 2009 10:33:06 -0500<br>> Subject: Re: [vtkusers] duplicated vertex in marching cubes?<br>> From: bill.lorensen@gmail.com<br>> To: dev_crisalix@hotmail.com<br>> CC: vtkusers@vtk.org<br>> <br>> Please provide a small, complete example. MC should not generate<br>> duplicate points or vertices. What is the datatype of your scalars?<br>> <br>> On Wed, Nov 11, 2009 at 10:20 AM, lucas Grijander<br>> <dev_crisalix@hotmail.com> wrote:<br>> ><br>> > Hi all!<br>> > I am using vtkMarchingCubes to calculate a 3D mesh of a volume I have. Fist<br>> > I initialize the filter with:<br>> > vtkMarchingCubes* iso = vtkMarchingCubes::New();<br>> > iso->SetInput(object);<br>> > iso->SetValue(0,1); // Surface #0, iso-value=1<br>> > iso->Update();<br>> > then I fill the vtkStructuredPoints.<br>> > The problem I have is, as you can see in the pictures, when you have a close<br>> > look to the trianbles (screen2) you can see duplicated triangles and vertex,<br>> > and this is a huge problem for my application... I supposed vtkMarchingCubes<br>> > should generate a single surface mesh... I don't know if that's the reason,<br>> > but when I fill the vtkStructuredPoints I use<br>> > scalars->InsertValue(cnt, 0) ; and scalars->InsertValue(cnt, 128) ;<br>> > I took all these from an example, I still don't know what you have to set as<br>> > values, either 1 or 128... in addition the result change with this number<br>> > and I'm not sure why.<br>> > What should I use as values? and also why I have this "double" triangles<br>> > mesh?<br>> > thanks!<br>> > Jaime.<br>> > ________________________________<br>> > Windows Live: Make it easier for your friends to see what you’re up to on<br>> > Facebook.<br>> > ________________________________<br>> > Keep your friends updated— even when you’re not signed in.<br>> > ________________________________<br>> > Windows Live: Friends get your Flickr, Yelp, and Digg updates when they<br>> > e-mail you.<br>> > _______________________________________________<br>> > Powered by www.kitware.com<br>> ><br>> > Visit other Kitware open-source projects at<br>> > http://www.kitware.com/opensource/opensource.html<br>> ><br>> > Please keep messages on-topic and check the VTK FAQ at:<br>> > http://www.vtk.org/Wiki/VTK_FAQ<br>> ><br>> > Follow this link to subscribe/unsubscribe:<br>> > http://www.vtk.org/mailman/listinfo/vtkusers<br>> ><br>> ><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>