Subject: [Viper-dev] [HG viper] Added cut plane and refactored codeto have two main variables; one vtkgrid that holds the original data, and filter holding the last filter in the pipe.

From: [email-masked]
Date: Tue, 12 Aug 2008 11:56:38 +0200 (CEST)

One or more new changesets pushed to the primary Viper repository.
A short summary of the last three changesets is included below.

changeset:   98:538fa1bae0b66c8d7e6d44c77963a7dd5a5407f3
tag:         tip
user:        "Ola Skavhaug <[email-masked]>"
date:        Tue Aug 12 11:58:51 2008 +0200
files:       ChangeLog src/demo/test.py src/demo/test_standalone.py src/viper/viper.py src/viper/viper_dolfin.py
description:
Added cut plane and refactored codeto have two main variables; one vtkgrid that holds the original data, and filter holding the last filter in the pipe.

changeset:   97:bf9e3b1bec7080ddfe35cfb18341af0f38d91e6c
user:        "Johan Hake <[email-masked]>"
date:        Mon Aug 11 23:34:24 2008 +0200
files:       src/viper/viper.py
description:
Implemented an interface to plot cut plane with viper

changeset:   96:fccb8772f1df18ee3aa7f976a6ed17a2ac3556d1
user:        "Ola Skavhaug <[email-masked]>"
date:        Mon Aug 11 13:17:04 2008 +0200
files:       ChangeLog
description:
Added ChangeLog

----------------------------------------------------------------------
For more details, visit http://www.fenics.org/hg/viper

---

From: Johan Hake <[email-masked]>
Date: Tue, 12 Aug 2008 12:38:40 +0200

On Tuesday 12 August 2008 11:56:38 [email-masked] wrote:
> files:       ChangeLog src/demo/test.py src/demo/test_standalone.py
> src/viper/viper.py src/viper/viper_dolfin.py description:
> Added cut plane and refactored codeto have two main variables; one vtkgrid
> that holds the original data, and filter holding the last filter in the
> pipe.

Nice!

I recognised a problem with not repositioning the camera after the cut, when 
the cut is _not_ done in the xy plane. Then the plane becomes invisable, 
untill the camera position is changed in interactive mode.

I think we need to reinterduce that feature.

Johan

> _______________________________________________
> Viper-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/viper-dev

---

From: Ola Skavhaug <[email-masked]>
Date: Tue, 12 Aug 2008 14:17:51 +0200

> I think we need to reinterduce that feature.

I see. The problem was that the implementation you provided did not seem to
set the camera angle correctly.

Ola

---

From: Johan Hake <[email-masked]>
Date: Tue, 12 Aug 2008 14:21:44 +0200

On Tuesday 12 August 2008 14:17:51 Ola Skavhaug wrote:
> > > Added cut plane and refactored codeto have two main variables; one
> > > vtkgrid that holds the original data, and filter holding the last
> > > filter in the pipe.
> >
> > Nice!
> >
> > I recognised a problem with not repositioning the camera after the cut,
> > when the cut is _not_ done in the xy plane. Then the plane becomes
> > invisable, untill the camera position is changed in interactive mode.
> >

That's correct, I am looking at it now.

Johan

---

From: Johan Hake <[email-masked]>
Date: Fri, 15 Aug 2008 08:42:41 +0200

On Tuesday 12 August 2008 14:21:44 Johan Hake wrote:
> > I see. The problem was that the implementation you provided did not seem
> > to set the camera angle correctly.
>

Here's the patch.

Could we make the axis optional. I think it is annoying.

Johan

> > > > ---------------------------------------------------------------------
> > > >- For more details, visit http://www.fenics.org/hg/viper

# HG changeset patch
# User "Johan Hake <[email-masked]>"
# Date 1218782372 -7200
# Node ID 9523af3969a054233f4e4ef5879b5e5f44d412e7
# Parent  8c0546e6c0f1398af66c7a61af3bc7db4bea0ff0
Corrected the camera view for a cutplane.

diff -r 8c0546e6c0f1 -r 9523af3969a0 src/viper/viper.py
--- a/src/viper/viper.py	Thu Aug 14 13:36:17 2008 +0200
+++ b/src/viper/viper.py	Fri Aug 15 08:39:32 2008 +0200
@@ -126,7 +126,37 @@
             # If plot a cut plane
             if not cutplane_origin is None:
                 self.filter = self._cutplane_filter(cutplane_origin, cutplane_normal)
-            (self.iren, self.renWin, self.ren) = self.simple_plotter(self.filter, vmin, vmax, wireframe)
+            (self.iren, self.renWin, self.ren) = self.simple_plotter(self.filter,
+                                                                     vmin, vmax,
+                                                                     wireframe)
+            if not cutplane_origin is None:
+                # Position the camera normal to the plane with focus on the center of the cutplane
+                cutplane_normal    = numpy.asarray(cutplane_normal,dtype = 'd')
+                camera_focal_point = numpy.asarray(self.filter.GetCenter(), dtype = 'd')
+                
+                #Normalize the cutplane normal
+                cutplane_normal /= numpy.sqrt(numpy.dot(cutplane_normal,cutplane_normal))
+                
+                # Check which component is the largest in the cutplane normal
+                if cutplane_normal.argmax() in [0,1]:
+                    # If the largest direction is in the x or y direction, let z be the up direction
+                    up_direction = numpy.array([0,0,1])
+                else:
+                    # If the largest direction is in the z direction, let y be the up direction
+                    up_direction = numpy.array([0,1,0])
+
+                # Set view_up as a projection of the cutplane normal onto the up_direction
+                # NOTE: Actually no need for the projection, vtk do the projection for you...
+                view_up = up_direction - numpy.dot(up_direction,cutplane_normal)*cutplane_normal
+                
+                # Set the camera position
+                self.ren.GetActiveCamera().SetPosition(camera_focal_point + cutplane_normal)
+                self.ren.GetActiveCamera().SetFocalPoint(camera_focal_point)
+                self.ren.GetActiveCamera().SetViewUp(view_up)
+                self.ren.ResetCamera(self.filter.GetBounds())
+                # It is sometimes nice to dolly the view but sometimes not
+                #self.ren.GetActiveCamera().Dolly(1.5) 
+            
         else:
             self.mode="vector"
             (self.iren, self.renWin, self.ren) = self.vector_plotter(self.filter, self.mesh.coordinates(), x, vmin, vmax, wireframe)

---

From: Johan Hake <[email-masked]>
Date: Thu, 21 Aug 2008 14:53:33 +0200

On Friday 15 August 2008 08:42:41 Johan Hake wrote:
> > > > I recognised a problem with not repositioning the camera after the
> > > > cut, when the cut is _not_ done in the xy plane. Then the plane
> > > > becomes invisable, untill the camera position is changed in
> > > > interactive mode.
> > > >
> > > I see. The problem was that the implementation you provided did not
> > > seem to set the camera angle correctly.
> >

Any respons?

Johan

---

From: Ola Skavhaug <[email-masked]>
Date: Thu, 21 Aug 2008 15:12:15 +0200

> > > That's correct, I am looking at it now.

Ah, I completely forgot. Will do soon.

Ola