[vtk-developers] potential speedup for the vtkpolydatatoimagestencil

Mark Roden mmroden at gmail.com
Wed Feb 29 17:10:27 EST 2012


It's ridiculously faster.  On the order of less than a second to load
all organs, rather than 30-60 seconds for all organs.

There does appear to be some issue with larger organs though-- looks
like some points are more than doubly linked.  I'm not sure why that
would be, unless the original contours are somehow corrupted.  I'm
looking into it.

On Wed, Feb 29, 2012 at 2:06 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> Out of curiosity, how much of a performance difference does it make?
>
>  - David
>
> On Wed, Feb 29, 2012 at 3:04 PM, Mark Roden <mmroden at gmail.com> wrote:
>> OK, I got it to work.
>>
>> For people who are following this thread, converting rtstructs from
>> vtkgdcmpolydata reader into a binary image but wanting to avoid
>> extrusion, this code will convert the data from polys to lines:
>>
>>
>> //just want lines returned, nothing else, for fast stenciling.
>> vtkPolyData* ConvertToLines(vtkPolyData * const data) {
>>    vtkPolyData* returnedData = vtkPolyData::New();
>>    returnedData->DeepCopy(data);
>>
>>    vtkPoints* newPoints = vtkPoints::New();
>>
>>    int theNumPoints = returnedData->GetNumberOfPoints();
>>
>>    if (theNumPoints == 1){
>>        double* pt = data->GetPoint(0);
>>        newPoints->InsertNextPoint(pt);
>>        returnedData->SetPoints(newPoints);
>>    } else {
>>
>>        int i;
>>        //borrowed this code from the polydatatostencil code
>>        //we know that each polygon is coplanar, so do that here.
>>        //also, closes the polygon, but should check to see if that's necessary.
>>        vtkMergePoints* theMerge = vtkMergePoints::New();
>>        double bounds[6];
>>        data->GetBounds(bounds);
>>        theMerge->InitPointInsertion(newPoints, bounds);
>>        vtkCellArray* polys = (data->GetPolys());
>>        vtkCellArray* lines = vtkCellArray::New();
>>        returnedData->SetLines(lines);//blank them out, just in case
>>        //each cell in the poly array is a polyline, I contend.
>>        int theNumPolys = polys->GetNumberOfCells();
>>        lines->Allocate(theNumPolys);
>>        polys->InitTraversal();
>>        vtkPoints* oldPoints = data->GetPoints();
>>        for (int j = 0; j < theNumPolys; j++){
>>            vtkIdType numPoints;
>>            vtkIdType* ptIds;
>>            polys->GetNextCell(numPoints, ptIds);
>>            lines->InsertNextCell(numPoints+1);//close the end of the poly
>>            int zeroPtId = 0;
>>            double zeroPt[3];
>>            for (i = 0; i < numPoints; i++){
>>              vtkIdType ptId;
>>              double point[3];
>>              oldPoints->GetPoint(ptIds[i], point);
>>              theMerge->InsertUniquePoint(point, ptId);
>>              lines->InsertCellPoint(ptId);
>>              newPoints->InsertNextPoint(point);
>>              if (i == 0){
>>                zeroPtId = ptId;
>>                zeroPt[0] = point[0];
>>                zeroPt[1] = point[1];
>>                zeroPt[2] = point[2];
>>              }
>>            }
>>            newPoints->InsertNextPoint(zeroPt);
>>            theMerge->InsertUniquePoint(zeroPt, zeroPtId);
>>            lines->InsertCellPoint(zeroPtId);//start from the beginning
>>        }
>>        returnedData->SetPoints(newPoints);
>>        returnedData->SetLines(lines);
>>        vtkCellArray* blank = vtkCellArray::New();
>>        returnedData->SetPolys(blank);
>>        blank->Delete();
>>        lines->Delete();
>>    }
>>    newPoints->Delete();
>>
>>    return returnedData;
>> }



More information about the vtk-developers mailing list