Re: More on VTK objects and mesh plotting with 3rd party packaages

2020-02-24 Thread Guyer, Jonathan E. Dr. (Fed) via fipy



> On Feb 23, 2020, at 8:43 AM, A A  wrote:
> 
> Uncommenting line 7 of the above code reveals that resetting the cell type 
> from 41 to 7 of the UniformGrid2D's underlying tvtk object allows the mesh to 
> appear in the plotter. 
> 
> I recall from previous discussions that failure of cell type 41 to plot was 
> attributed to incorrect ordering of the cell vertices, but this would be in 
> contradiction with the results of the code above.


>From the [VTK 
>documentation](https://vtk.org/doc/release/4.2/html/classvtkConvexPointSet.html),
> "vtkConvexPointSet is a concrete implementation that represents a 3D cell 
>defined by a convex set of points." FiPy does not output vertices correctly 
>for this 3D object. The fact that a Grid2D outputs its vertices in the correct 
>order for a VTK_POLYGON does not change the fact that the ordering is wrong 
>for VTK_CONVEX_POINT_SET.

The docstring for UniformGrid2D._calcOrderedCellVertexIDs says "Correct 
ordering for VTK_PIXEL", but it does not do this. It produces the ordering for 
VTK_QUAD (which also works for VTK_POLYGON).

The docstring for UniformGrid3D._calcOrderedCellVertexIDs correctly states 
"Correct ordering for `VTK_VOXEL`".

The proper interim fix is to make the following changes:

diff --git a/fipy/meshes/nonUniformGrid3D.py b/fipy/meshes/nonUniformGrid3D.py
index 8e78c5319..03097e2b7 100644
--- a/fipy/meshes/nonUniformGrid3D.py
+++ b/fipy/meshes/nonUniformGrid3D.py
@@ -116,6 +116,14 @@ class NonUniformGrid3D(Mesh):
 faceTangents2[2, self.numberOfXYFaces + self.numberOfXZFaces:] = 1.
 return faceTangents1, faceTangents2
 
+@property
+def _VTKCellType(self):
+try:
+from tvtk.api import tvtk
+except ImportError as e:
+from enthought.tvtk.api import tvtk
+return tvtk.Voxel().cell_type
+
 ## The following method is broken when dx, dy or dz are not scalar. Simpler to 
use the generic
 ## _calcFaceAreas rather than do the required type checking, resizing and 
outer product.
 ##
diff --git a/fipy/meshes/uniformGrid1D.py b/fipy/meshes/uniformGrid1D.py
index 041f8ed9d..931f3f708 100644
--- a/fipy/meshes/uniformGrid1D.py
+++ b/fipy/meshes/uniformGrid1D.py
@@ -288,6 +288,14 @@ class UniformGrid1D(UniformGrid):
 c1 = numerix.arange(self.numberOfCells)
 return numerix.array((c1 + 1, c1))
 
+@property
+def _VTKCellType(self):
+try:
+from tvtk.api import tvtk
+except ImportError as e:
+from enthought.tvtk.api import tvtk
+return tvtk.Line().cell_type
+
 def _getNearestCellID(self, points):
 """
 Test cases
diff --git a/fipy/meshes/uniformGrid2D.py b/fipy/meshes/uniformGrid2D.py
index 16815c689..37d3ebfa6 100644
--- a/fipy/meshes/uniformGrid2D.py
+++ b/fipy/meshes/uniformGrid2D.py
@@ -560,6 +560,14 @@ class UniformGrid2D(UniformGrid):
 
 return ids.reshape((4, self.numberOfCells), order='F')
 
+@property
+def _VTKCellType(self):
+try:
+from tvtk.api import tvtk
+except ImportError as e:
+from enthought.tvtk.api import tvtk
+return tvtk.Quad().cell_type
+
 def _getNearestCellID(self, points):
 """
 Test cases
diff --git a/fipy/meshes/uniformGrid3D.py b/fipy/meshes/uniformGrid3D.py
index 4ad7a3b69..29990f53e 100644
--- a/fipy/meshes/uniformGrid3D.py
+++ b/fipy/meshes/uniformGrid3D.py
@@ -491,6 +491,14 @@ class UniformGrid3D(UniformGrid):
 
 return numerix.reshape(ids.swapaxes(1, 3), (8, self.numberOfCells))
 
+@property
+def _VTKCellType(self):
+try:
+from tvtk.api import tvtk
+except ImportError as e:
+from enthought.tvtk.api import tvtk
+return tvtk.Voxel().cell_type
+
 ## scaling
 
 def _getNearestCellID(self, points):


This will fix the Grid classes. It definitely doesn't fix arbitrary 3D meshes.
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: More on VTK objects and mesh plotting with 3rd party packaages

2020-02-24 Thread Guyer, Jonathan E. Dr. (Fed) via fipy
AbstractMesh is abstract. It makes no assumptions about geometry, topology, or 
dimensionality. Forcing it to render as VTK_POLYGON, an intrinsically 2D 
object, is not appropriate.

> On Feb 23, 2020, at 8:43 AM, A A  wrote:
> 
> Dear All,
> 
> This question is loosely related to 
> https://github.com/usnistgov/fipy/issues/312 but might perhaps not be exactly 
> the same. I ran some tests in which I tried to plot a "broken" mesh by 
> resetting the cell type of the underlying tvtk object the same way fipy's 
> VTKCellDataSet method does:
> 
> from fipy import Grid2D
> import pyvista
> 
> # Create Mesh
> mesh = Grid2D(dx = 1.0, dy = 1.0, nx = 2, ny = 2)
> ug = mesh.VTKCellDataSet
> #ug.set_cells([7,7,7,7], ug.cell_locations_array.to_array(), ug.get_cells()) 
> # overwrite to
> ugrid= pyvista.UnstructuredGrid(ug._vtk_obj)
> 
> # Plot Mesh
> plotter = pyvista.Plotter()
> plotter.set_background('white')
> plotter.add_mesh(ugrid, style='wireframe', color='black')
> plotter.add_bounding_box(color='red')
> 
> plotter.view_xy()
> plotter.show()
> 
> Uncommenting line 7 of the above code reveals that resetting the cell type 
> from 41 to 7 of the UniformGrid2D's underlying tvtk object allows the mesh to 
> appear in the plotter. 
> 
> I recall from previous discussions that failure of cell type 41 to plot was 
> attributed to incorrect ordering of the cell vertices, but this would be in 
> contradiction with the results of the code above.
> 
> I then looked through fipy's source code and came up with the following 
> inheritance diagram:
> 
> 
> The _VTKCellType method in AbstractMesh returns 
> tvtk.ConvexPointSet().cell_type while the  _VTKCellType method in Mesh2D 
> returns tvtk.Polygon().cell_type. I am quite sure that forcing AbstractMesh 
> to return  tvtk.Polygon().cell_type would cause the UniformGrid2D object to 
> appear in pyvista/mayavi, though I am not sure whether this is a viable 
> solution. Any thoughts?
> 
> Regards,
> 
> Amine
> 
> ___
> fipy mailing list
> fipy@nist.gov
> http://www.ctcms.nist.gov/fipy
>  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]