[vtkusers] Using vtkPolyDataReader with vtkClipPolyData
Bill Lorensen
bill.lorensen at gmail.com
Fri Feb 17 15:34:37 EST 2012
Once you compute the normal as Alan illustrated you can use vtkPlane
to define an implicit function (SetClipFunction) for vtkClipPolyData.
On Fri, Feb 17, 2012 at 8:46 AM, Alan Smithee <xtreme2k2 at web.de> wrote:
> Hi Chris!
>
> A plane is defined by three points and that is what you have. Take two of
> them and make the cross product, since the cross product is a vector which
> is orthogonal to both. In principal this cross product vector is the normal.
>
> Or you use the static function ComputeNormal of vtkTriangle:
>
> double P1[3] = { p1[0], p1[1], p1[2] };
> double P2[3] = { p2[0], p2[1], p2[2] };
> double P3[3] = { p3[0], p3[1], p[2] };
>
> double n[3];
> vtkTriangle::ComputeNormal(P1, P2, P3, n);
>
> Am 16.02.2012 23:59, schrieb Bayliss, Chris (Chicago):
>
> 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()->GetOutput());*/
>
>
> trimpd->GetCellData()->SetNormals(trimnorm->GetOutput()->GetCellData()->GetNormals());
>
> trimpd->Update();
>
>
>
> ///////// Get cell normals ///////////
>
> vtkDoubleArray *cellNormalsRetrieved =
> vtkDoubleArray::SafeDownCast(trimpd/*->GetOutput()*/->GetCellData()->GetNormals());
>
> 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 ************************
>
> _______________________________________________
> 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
>
>
>
> _______________________________________________
> 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
>
--
Unpaid intern in BillsBasement at noware dot com
More information about the vtkusers
mailing list