[vtkusers] duplicated vertex in marching cubes?

Bill Lorensen bill.lorensen at gmail.com
Wed Nov 11 10:51:14 EST 2009


Try iso->SetValue(0,64);

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



More information about the vtkusers mailing list