[vtkusers] vtkPolyDataNormals?

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Wed Apr 28 17:24:57 EDT 2004


Hi Larry,
   looks like you are making good progress. I dont know the details of how
vtkPolyDataNormals orders points, I would read the documentation carefully,
and then take a look at the source code structure and comments. It is
possible the algorithm can ensure consistency but does not really know
inside/outside so perhaps the first cell dictates. If your polygons were
correctly ordered to start with you would not need vtkPolyDataNormals.
I still think you may have to resort to some OpenGL to really solve this
for hidden (and partly hidden) polygons.
  Dave P



|---------+---------------------------->
|         |           "Larry"          |
|         |           <larry74 at 163.com>|
|         |           Sent by:         |
|         |           vtkusers-admin at vt|
|         |           k.org            |
|         |                            |
|         |                            |
|         |           29/04/2004 01:52 |
|         |                            |
|---------+---------------------------->
  >--------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                                |
  |       To:       <vtkusers at vtk.org>                                                                                             |
  |       cc:                                                                                                                      |
  |       Subject:  [vtkusers] vtkPolyDataNormals?                                                                                 |
  >--------------------------------------------------------------------------------------------------------------------------------|




Hello, Dave!

Could you tell me how the vtkPolyDataNormals order its cell points?
Since when I use it with ConsistencyOn, it returns different orientation
for
different shape,
for convex shape(base shape on the floor, the 3d object is standing
perpedicular to the floor), it point outside the object, so when I use dot
product with camera position vector, it return the front faces
**********
*                *
**********

but for such a shape, the normals point inside the object, so when I use
dot
product with camera vector, it returns the back faces.
*************
*                      *
*        ********
*        *
*        *
*        *********
*                        *
**************

Is there a way that can make the noram always point outside the object?
Or is there anything wrong with my code as following,
vtkPolyDataNormals cowNormals = new vtkPolyDataNormals();

cowNormals.ConsistencyOn();

cowNormals.SplittingOff();

cowNormals.FlipNormalsOff();

cowNormals.SetInput(polydata);

cowNormals.Update();

vtkPolyData orderedPoly = cowNormals.GetOutput();

vtkPolyData newPoly2 = new vtkPolyData();

newPoly2.Allocate(orderedPoly .GetNumberOfCells(), orderedPoly
.GetNumberOfCells());

newPoly2.SetPoints(orderedPoly .GetPoints());

int numOfCells = orderedPoly .GetNumberOfCells();

vtkPoints points = orderedPoly .GetPoints();

for (int i = 0; i < numOfCells; i++)

{

vtkCell cell = orderedPoly .GetCell(i);

vtkPoints pts = cell.GetPoints();

if(cell.GetCellType() != 5) continue;

vtkTriangle tcell = (vtkTriangle)cell;

double normal[] = new double[3];

tcell.ComputeNormal(pts.GetPoint(0),pts.GetPoint(1),
pts.GetPoint(2),normal);

double[] p0 = pts.GetPoint(0);

double[] cameraVector = new
double[]{cameraPosition[0]-p0[0],cameraPosition[1]-p0[1],cameraPosition[2]-p

0[2]};

double dotProduct = normal[0]*cameraVector[0]
+normal[1]*cameraVector[1]+normal[2]*cameraVector[2];

if(dotProduct > 0)

    newPoly2.InsertNextCell(tcell.GetCellType(), tcell.GetPointIds());

}

Thanks very much.
Best Regards,
Larry.

----- Original Message -----
From: <David.Pont at ForestResearch.co.nz>
To: "Larry" <larry74 at 163.com>
Cc: <vtkusers at vtk.org>
Sent: Sunday, April 25, 2004 10:19 PM
Subject: Re: [vtkusers] How to get the visible face?


>
> Hi Larry,
>
> 1:  you can use an instance of vtkPolygon to calculate a normal
>       float cNormal[3];
>       vtkPoints *pts = cell->GetPoints();
>       vtkPolygon::ComputeNormal( pts, cNormal );
> To tidy cell:point ordering pass the polydata through vtkPolyDataNormals
> with ConsistencyOn, which will: "... reorder polygons to insure
consistent
> orientation across polygon neighbors."
>
> 2:  I have no experience with vtk from Java. Note that
> vtkCell::IntersectWithLine is virtual and is implemented in descendants
> such as vtkTriangle.
>
>     Dave P.
>
>
>
> |---------+---------------------------->
> |         |           "Larry"          |
> |         |           <larry74 at 163.com>|
|
> |         |           23/04/2004 20:54 |
> |         |                            |
> |---------+---------------------------->
>
>---------------------------------------------------------------------------

-----------------------------------------------------|
>   |
|
>   |       To:       <David.Pont at ForestResearch.co.nz>
|
>   |       cc:       <vtkusers at vtk.org>
|
>   |       Subject:  Re: [vtkusers] How to get the visible face?
|
>
>---------------------------------------------------------------------------

-----------------------------------------------------|
>
>
>
>
> Hello, Dave,
>
> Thank you very much for your reply, it's very helpful!
>
> But I am still not very clear how to do it, I am new to this.
>
> 1.How to do caculate the normal?
> suppose the cell has 3 points, p0,p1,p2
> the normal could be caculated as n=(p1-p0)X(p2-p0).
> but the 3 points maybe in any order, so the normal vector could point to
> any
> direction(to inside or outside to the 3d object). Then the dot product
with
> camera vector(cameraPoint - p0) could be - or +.
>
> ps., those triangles face of 3d object is generated by vtk, after cut by
> planes.
>
> 2. vtkCell::IntersectWithLine
> I am using vtk4.2 with Java wrapper, I can not see this method. But I can
> find it in the html document of vtk4.0, is that meant that the latest
> version doesn't support this method.
>
> And again thanks for your kind help!
>
> Best Regards,
> Larry
>
> ----- Original Message -----
> From: <David.Pont at ForestResearch.co.nz>
> To: "Larry" <larry74 at 163.com>
> Cc: <vtkusers at vtk.org>
> Sent: Thursday, April 22, 2004 11:31 PM
> Subject: Re: [vtkusers] How to get the visible face?
>
>
> >
> > Hi Larry,
> >    you could traverse all cells, get or calculate a cell normal and use
> dot
> > product with camera vector. To handle occlusion would be more tricky...
> >   Dave P
> >
> >
> > |---------+---------------------------->
> > |         |           "Larry"          |
> > |         |           <larry74 at 163.com>|
> > |         |           vtkusers-admin at vt|
> > |         |           k.org            |
> > |         |                            |
> > |         |                            |
> > |         |           23/04/2004 02:10 |
> > |         |                            |
> > |---------+---------------------------->
> >
>
>---------------------------------------------------------------------------

>
> -----------------------------------------------------|
> >   |
> |
> >   |       To:       <vtkusers at vtk.org>
> |
> >   |       cc:
> |
> >   |       Subject:  [vtkusers] How to get the visible face?
> |
> >
>
>---------------------------------------------------------------------------

>
> -----------------------------------------------------|
> >
> >
> >
> >
> > Hello, everyone!
> > Suppose I have a polydata, which is consisted of triangles, I'd like to
> get
> > the faces which can be seen by the camera.
> > That's to say, there is a point M, and an object whose faces is a set
of
> > triangles, How can I get the faces that can be seen by the point M? and
> how
> > can I get the faces that is not seen by the point M?
> >
> > Thanks!
> > Larry
> > _
> >
> >
> >
> >
> >
>
>
>
> _
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>


_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: <
http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

_







More information about the vtkusers mailing list