[vtkusers] Get crashed during initializing vtkContourWidget

Xiaopeng Yang yxp233 at postech.ac.kr
Tue Mar 15 22:08:27 EDT 2011


Dear Users,

 

I generated polylines from vtkstripper and used it  to initialize
vtkcontourwidget. In the code, "pd2" is the polylines I generated. It worked
when I used "pd2" to initialize vtkcontourwidget. But there were so many
control points. So I applied vtkdecimatepolylinefilter to decrease the
number of control points. But when I used the decimated polylines "pd3" to
initialize vtkcontourwidget, the program just got crashed. I cannot find
where I made a mistake. Please give me a hand. Thanks.

 

         vtkMarchingContourFilter *contourFilter =
vtkMarchingContourFilter::New();

         contourFilter->SetValue(0, 128.0);

         contourFilter->ComputeNormalsOff();

         contourFilter->ComputeGradientsOff();

         contourFilter->UseScalarTreeOn();

         contourFilter->SetInput( connector2->GetOutput() );

 

         vtkStripper *stripper = vtkStripper::New(); 

         stripper->SetInput(contourFilter->GetOutput()); 

         stripper->Update(); 

 

         vtkPolyData * pd = vtkPolyData::New();

         pd = stripper->GetOutput();

         

         vtkPoints * pts = pd->GetPoints();

 

         double zPos = static_cast<double> ( origin[2]) + (
static_cast<double> (112)*spacing[2]);

              

         for (int j = 0; j < pd->GetNumberOfPoints(); j++)

         {

                    double point[3];

                    pts->GetPoint(j, point);

                    point[2] = zPos;

                    pts->SetPoint(j,point);

         }

 

         vtkCellArray * lines = pd->GetLines();

         vtkIdType numPoints;

         vtkIdType *points;

         

         vtkPoints *tmpPoints = vtkPoints::New();

               

         while (lines->GetNextCell(numPoints, points) !=0)

         {

                    

               for (int j = 0; j < numPoints; j++)

               {

                   double point[3];

                   pts->GetPoint(points[j],point);

                   tmpPoints->InsertNextPoint(point);

               }

         }

 

         vtkPolyData *pd2 = vtkPolyData::New();  

         pd2->SetPoints(tmpPoints);

         pd2->SetLines(lines);

 

         vtkDecimatePolylineFilter *decimate =
vtkDecimatePolylineFilter::New();

         decimate->SetInput(pd2);

         decimate->SetTargetReduction(0.9);

         decimate->Update();

 

         vtkPolyData *pd3 = vtkPolyData::New();

         pd3 = decimate->GetOutput();

               

         ContourWidget = vtkSmartPointer<vtkContourWidget>::New(); 

         rep =
vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New(); 

 

         ContourWidget->SetInteractor(iren);

         ContourWidget->SetRepresentation(rep);

 

         rep->GetProperty()->SetColor(1,0,1);

         rep->GetProperty()->SetPointSize(5);

         rep->GetLinesProperty()->SetColor(0,1,1);

         rep->GetLinesProperty()->SetLineWidth(3);

 

         ContourWidget->On();

         ContourWidget->Initialize(pd3);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110316/05c3face/attachment.htm>


More information about the vtkusers mailing list