[vtkusers] Using vtkPolyDataReader with vtkClipPolyData

Bayliss, Chris (Chicago) cbayliss at gnresound.com
Thu Feb 16 17:59:23 EST 2012


Hi,

 

I am having trouble extracting the appropriate data from a .vtk polydata
file and using it with vtkClipPolyData.  My polydata file contains three
points representing a plane, the file contents are shown below.

 

(Sample1-plane.vtk)

 

# vtk DataFile Version 3.0

vtk output

ASCII

DATASET POLYDATA

POINTS 3 float

-2.31291 -0.472235 -26.3682 27.227 -13.8288 4.74193 -29.2774 -4.23973
-2.38224 

 

VERTICES 3 6

1 0 

1 1 

1 2

 

 

I am not sure how to read/extract this data and convert it into a usable
form for the vtkclipPolyData filter.  My code is below.  Does anyone
know how to compute the origin and normal vector form the polydata file
above?  

 

 

 

//import polydata file from above:

vtkPolyDataReader *trim =vtkPolyDataReader::New();

   trim->SetFileName("C:/Program
Files/VTK/TPS/Debug/Sample1-plane.vtk"); 

   trim->Update();

   

   //Convert vtkpolydatareader object to vtkpolydata

   vtkPolyData* trimpd = trim->GetOutput();

   trimpd->SetPoints(trim->GetOutput()->GetPoints());

   trimpd->SetVerts(trim->GetOutput()->GetVerts());

   trimpd->SetPolys(trim->GetOutput()->GetPolys());

   trimpd->Update();

 

// Write all of the coordinates of the points in the vtkPolyData to the
console.

    for(vtkIdType a = 0; a < trimpd->GetNumberOfPoints(); a++)

      {

      double p[3];

      trimpd->GetPoint(a,p);

      // This is identical to:

      // polydata->GetPoints()->GetPoint(i,p);

      std::cout << "Points in trim plane " << a << " : (" << p[0] << " "
<< p[1] << " " << p[2] << ")" << std::endl;

      }

 

 

//Compute plane normal

   vtkPolyDataNormals *trimnorm = vtkPolyDataNormals::New();

   trimnorm->SetInput(trimpd);

   trimnorm->ComputePointNormalsOn();

   trimnorm->ComputePointNormalsOn();

   trimnorm->ComputeCellNormalsOn();

   trimnorm->Update();

 

 
/*trimpd->GetCellData()->SetNormals(trimnorm->ComputeCellNormalsOn()->Ge
tOutput());*/

 
trimpd->GetCellData()->SetNormals(trimnorm->GetOutput()->GetCellData()->
GetNormals());

   trimpd->Update();

 

///////// Get cell normals ///////////

  vtkDoubleArray *cellNormalsRetrieved =
vtkDoubleArray::SafeDownCast(trimpd/*->GetOutput()*/->GetCellData()->Get
Normals());

  if(cellNormalsRetrieved)

    { 

    cout << "There are " << cellNormalsRetrieved->GetNumberOfTuples() <<
" cell normals." << endl;

    for(vtkIdType i = 0; i < cellNormalsRetrieved->GetNumberOfTuples();
i++)

      {

      double cN[3];

      cellNormalsRetrieved->GetTuple(i, cN);

      cout << "Cell normal " << i << ": " << cN[0] << " " << cN[1] << "
" << cN[2] << endl;

      }

    }

  else

    {

    cout << "No cell normals." << endl;

    }

 

//Create trim plane from polydata:

vtkPlane *trimplane = vtkPlane::New();

   trimplane->SetOrigin(trimpd->GetPoint(0));

   trimplane->SetNormal(0.0, 1.0, 0.0);//made up values, would like to
use output of vtkpolydatanormals somehow.

//clip polydata named "warp": 

   vtkClipPolyData *clipper = vtkClipPolyData::New();

   clipper->SetInputConnection(warp->GetOutputPort());

   clipper->SetClipFunction(trimplane);

   clipper->GenerateClippedOutputOn();

   clipper->SetValue(0.5);

 

Thanks,

 

Chris


**** GN GROUP NOTICE - AUTOMATICALLY INSERTED **** 
The information in this e-mail (including attachments, if any) is considered confidential and is intended only for the recipient(s) listed above. Any review, use, disclosure, distribution or copying of this e-mail is prohibited except by or on behalf of the intended recipient. If you have received this email in error, please notify me immediately by reply e-mail, delete this e-mail, and do not disclose its contents to anyone. Any opinions expressed in this e-mail are those of the individual and not necessarily the GN group. Thank you. 
******************** DISCLAIMER END ************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120216/0b42cc13/attachment.htm>


More information about the vtkusers mailing list