[vtkusers] vtkImageDataGeometryFilter cells reconstruction issue

Sebastien Calvi sebastien.calvi at yahoo.com
Wed Mar 14 11:46:13 EDT 2012


Hello All,

I've been working lately with the vtkImageDataGeometryFilter and after some debug I came to the conclusion that:
inside the RequestData(...) method, when dimension == 2 (build plane) if one checks for ThresholdCells, this logic is INVERTED:
            threshok = false;
            for (s=0; !threshok && s<4; s++)
              {
              if (pointScalars->GetComponent(ptIds[s],0)>this->ThresholdValue)
                {
                  threshok = true;
                  break;
                }
              }
This only check if at least one vertex is above the threshold but the other way around might be more judicious:

                    threshok = true;
                    firstTriangle = true;

                    for ( s = 0; threshok && s < 4; s++ ) {

                        if ( pointScalars->GetComponent( ptIds[s], 0 ) <= this->ThresholdValue ) {

                            if ( s == 1 ) {
                                firstTriangle = false;
                            } else {
                                threshok = false;
                                break;
                            }
                        }
                    }


As you can see I have also added a firstTriangle var which allows to conserve at least one of the two triangles if possible...

Find below the portion of code that I propose to modify:
                if ( this->ThresholdCells ) {
                    threshok = true;
                    firstTriangle = true;

                    for ( s = 0; threshok && s < 4; s++ ) {

                        if ( pointScalars->GetComponent( ptIds[s], 0 ) <= this->ThresholdValue ) {

                            if ( s == 1 ) {
                                firstTriangle = false;
                            } else {
                                threshok = false;
                                break;
                            }
                        }
                    }

                    if ( threshok ) {

                        if ( this->OutputTriangles ) {

                            if ( firstTriangle ) {
                                cellId = newPolys->InsertNextCell( 3, ptIds );
                                outCD->CopyData( cd, idx, cellId );
                            }

                            triIds[0] = ptIds[0];
                            triIds[1] = ptIds[2];
                            triIds[2] = ptIds[3];
                            cellId = newPolys->InsertNextCell( 3, triIds );
                            outCD->CopyData( cd, idx, cellId );
                        } else {
                            cellId = newPolys->InsertNextCell( 4, ptIds );
                            outCD->CopyData( cd, idx, cellId );
                        }
                    }
                } else {
                    cellId = newPolys->InsertNextCell( 4, ptIds );
                    outCD->CopyData( cd, idx, cellId );
                }


The var firstTriangle has to be declared outside of the switch scope of course.
For now that is how I have modified/customized my own filter.

Remark:
- the UpdateProgress calls are missing in this filter (I've also added it in my own implementation).

Other Remark:
- I use register for loop vars and it improves performances :)

Alright, let me know if I'm right or wrong about this filter and let me know if you want me to post my final work about it or if these snipets are good enough, okay?

Thank you,
Sebastien.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120314/7d5df651/attachment.htm>


More information about the vtkusers mailing list